• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geo-engine / geoengine / 10178074589

31 Jul 2024 09:34AM UTC coverage: 91.068% (+0.4%) from 90.682%
10178074589

push

github

web-flow
Merge pull request #973 from geo-engine/remove-XGB-update-toolchain

Remove-XGB-update-toolchain

81 of 88 new or added lines in 29 files covered. (92.05%)

456 existing lines in 119 files now uncovered.

131088 of 143945 relevant lines covered (91.07%)

53581.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.77
/datatypes/src/plots/scatter_plot.rs
1
use crate::plots::{Plot, PlotData, PlotMetaData};
2
use crate::primitives::Coordinate2D;
3
use crate::util::Result;
4
use serde::{Deserialize, Serialize};
5

6
/// A scatter plot consists of a series of `Coordinate`s
UNCOV
7
#[derive(Debug, Deserialize, Serialize)]
×
8
#[serde(rename_all = "camelCase")]
9
pub struct ScatterPlot {
10
    title_x: String,
11
    title_y: String,
12
    values: Vec<Coordinate2D>,
13
}
14

15
impl ScatterPlot {
16
    /// Creates a new scatter plot without points.
17
    pub fn new(title_x: String, title_y: String) -> ScatterPlot {
8✔
18
        Self::new_with_data(title_x, title_y, vec![])
8✔
19
    }
8✔
20

21
    /// Creates a new scatter plot with the given data points.
22
    pub fn new_with_data(
14✔
23
        title_x: String,
14✔
24
        title_y: String,
14✔
25
        values: Vec<Coordinate2D>,
14✔
26
    ) -> ScatterPlot {
14✔
27
        ScatterPlot {
14✔
28
            title_x,
14✔
29
            title_y,
14✔
30
            values,
14✔
31
        }
14✔
32
    }
14✔
33

34
    /// Adds the given points to this scatter plot
35
    pub fn update_batch(&mut self, values: impl Iterator<Item = Coordinate2D>) {
1✔
36
        for i in values {
251✔
37
            self.update(i);
250✔
38
        }
250✔
39
    }
1✔
40

41
    /// Adds a new point to this scatter plot.
42
    pub fn update(&mut self, value: Coordinate2D) {
270✔
43
        self.values.push(value);
270✔
44
    }
270✔
45
}
46

47
impl Plot for ScatterPlot {
48
    fn to_vega_embeddable(&self, _allow_interactions: bool) -> Result<PlotData> {
13✔
49
        let vega_spec = serde_json::json!({
13✔
50
            "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
13✔
51
            "width": "container",
13✔
52
            "height": "container",
13✔
53
            "data": { "values": self.values },
13✔
54
            "mark": "point",
13✔
55
             "encoding": {
13✔
56
                "x": {"field": "x", "type": "quantitative", "title": self.title_x},
13✔
57
                "y": {"field": "y", "type": "quantitative", "title": self.title_y}
13✔
58
             }
13✔
59
        });
13✔
60

13✔
61
        Ok(PlotData {
13✔
62
            vega_string: vega_spec.to_string(),
13✔
63
            metadata: PlotMetaData::None,
13✔
64
        })
13✔
65
    }
13✔
66
}
67

68
#[cfg(test)]
69
mod tests {
70
    use crate::plots::scatter_plot::ScatterPlot;
71
    use crate::plots::Plot;
72
    use crate::primitives::Coordinate2D;
73

74
    #[test]
75
    fn test_ser() {
1✔
76
        let mut sp = ScatterPlot::new("X-Axis".to_string(), "Y-Axis".to_string());
1✔
77
        for i in 1..=5 {
6✔
78
            sp.update(Coordinate2D::new(f64::from(i), f64::from(i)));
5✔
79
        }
5✔
80

81
        let ser = serde_json::to_string(&sp).unwrap();
1✔
82

1✔
83
        let expected = serde_json::json!({
1✔
84
            "titleX": "X-Axis",
1✔
85
            "titleY": "Y-Axis",
1✔
86
            "values": [
1✔
87
                { "x": 1.0, "y": 1.0 }, { "x": 2.0, "y": 2.0 }, { "x": 3.0, "y": 3.0 }, { "x": 4.0, "y": 4.0 }, { "x": 5.0, "y": 5.0 }
1✔
88
            ]
1✔
89
        });
1✔
90

1✔
91
        assert_eq!(expected.to_string(), ser);
1✔
92
    }
1✔
93

94
    #[test]
95
    fn test_vega() {
1✔
96
        let mut sp = ScatterPlot::new("X-Axis".to_string(), "Y-Axis".to_string());
1✔
97
        for i in 1..=5 {
6✔
98
            sp.update(Coordinate2D::new(f64::from(i), f64::from(i)));
5✔
99
        }
5✔
100

101
        let ser = sp.to_vega_embeddable(false).unwrap().vega_string;
1✔
102

1✔
103
        let expected = serde_json::json!({
1✔
104
            "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
1✔
105
            "width": "container",
1✔
106
            "height": "container",
1✔
107
            "data": { "values": [
1✔
108
                { "x": 1.0, "y": 1.0 }, { "x": 2.0, "y": 2.0 }, { "x": 3.0, "y": 3.0 }, { "x": 4.0, "y": 4.0 }, { "x": 5.0, "y": 5.0 }
1✔
109
            ] },
1✔
110
            "mark": "point",
1✔
111
             "encoding": {
1✔
112
                "x": {"field": "x", "type": "quantitative", "title": "X-Axis"},
1✔
113
                "y": {"field": "y", "type": "quantitative", "title": "Y-Axis"}
1✔
114
             }
1✔
115
        });
1✔
116

1✔
117
        assert_eq!(expected.to_string(), ser);
1✔
118
    }
1✔
119
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc