Skip to content

Commit d964314

Browse files
committed
Improve the known issue.
1 parent 8a07b4a commit d964314

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

plotters/src/element/basic_shapes.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl<I0: Iterator + Clone, Size: SizeDesc, DB: DrawingBackend> Drawable<DB>
189189
};
190190
let size = self.size.in_pixels(&ps).max(0) as f32;
191191
let spacing = self.spacing.in_pixels(&ps).max(0) as f32;
192+
let mut is_previous_solid = false;
192193
for curr in points {
193194
let curr_f = to_f(curr);
194195
let (dx, dy) = (curr_f.0 - start.0, curr_f.1 - start.1);
@@ -199,6 +200,11 @@ impl<I0: Iterator + Clone, Size: SizeDesc, DB: DrawingBackend> Drawable<DB>
199200
// 1) o-- -- o (need to patch last one)
200201
// 2) o-- -- o (ignore the last one)
201202
// 3) o o (points are too dense)
203+
if is_previous_solid {
204+
start.0 += dx * gap_scale;
205+
start.1 += dy * gap_scale;
206+
d -= spacing;
207+
}
202208
while d >= size {
203209
// Solid line
204210
let end = (start.0 + dx * scale, start.1 + dy * scale);
@@ -210,8 +216,10 @@ impl<I0: Iterator + Clone, Size: SizeDesc, DB: DrawingBackend> Drawable<DB>
210216
// Finish the last segment
211217
// 1) o-- -- -o (patched)
212218
// 2) o-o (become solid line)
213-
if d > 0. {
214-
backend.draw_path([to_i(start), curr], &self.style)?;
219+
let line = [to_i(start), curr];
220+
is_previous_solid = d > 0. && line[0] != line[1];
221+
if is_previous_solid {
222+
backend.draw_path(line, &self.style)?;
215223
}
216224
// Move to the current point
217225
start = curr_f;
@@ -226,14 +234,15 @@ fn test_dashed_path_element() {
226234
use crate::prelude::*;
227235
let check_list = std::cell::RefCell::new(vec![
228236
[(100, 100), (100, 103)],
229-
[(100, 103), (100, 108)],
230-
[(100, 110), (100, 115)],
231-
[(100, 117), (100, 120)],
237+
[(100, 105), (100, 110)],
238+
[(100, 112), (100, 117)],
239+
[(100, 119), (100, 120)],
232240
]);
233241
let da = crate::create_mocked_drawing_area(300, 300, |m| {
234242
m.check_draw_path(move |c, s, path| {
235243
assert_eq!(c, BLUE.to_rgba());
236244
assert_eq!(s, 7);
245+
dbg!(&path);
237246
assert_eq!(path, check_list.borrow_mut().remove(0));
238247
});
239248
m.drop_check(|b| {

plotters/src/series/line_series.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ mod test {
144144
});
145145

146146
m.drop_check(|b| {
147-
assert_eq!(b.num_draw_path_call, 51);
148-
assert_eq!(b.draw_count, 51);
147+
assert_eq!(b.num_draw_path_call, 26);
148+
assert_eq!(b.draw_count, 26);
149149
});
150150
});
151151

0 commit comments

Comments
 (0)