Skip to content

Commit e85d712

Browse files
committed
Fix bug #93 and add test cases
1 parent 6ff1f2b commit e85d712

File tree

3 files changed

+52
-25
lines changed

3 files changed

+52
-25
lines changed

Cargo.toml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ readme = "README.md"
1212
exclude = ["doc-template/*"]
1313

1414
[dependencies]
15-
num-traits = "^0.2"
16-
chrono = { version = "0.4.9", optional = true }
17-
gif = { version = "^0.10.3", optional = true }
15+
num-traits = "0.2.10"
16+
chrono = { version = "0.4.10", optional = true }
17+
gif = { version = "0.10.3", optional = true }
1818

1919
[dependencies.palette]
20-
version = "^0.5"
20+
version = "0.5.0"
2121
default-features = false
2222
optional = true
2323
features = ["std"]
2424

2525
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
26-
rusttype = {version = "0.8.1", optional = true}
27-
lazy_static = {version = "^1.2", optional = true }
28-
font-kit = {version = "0.5.0", optional = true }
29-
piston_window = {version = "0.105.0", optional = true}
26+
rusttype = { version = "0.8.2", optional = true }
27+
lazy_static = { version = "1.4.0", optional = true }
28+
font-kit = { version = "0.5.0", optional = true }
29+
piston_window = { version = "0.105.0", optional = true }
3030

3131
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.image]
3232
version = "0.22.3"
@@ -40,11 +40,11 @@ optional = true
4040
features = ["ps"]
4141

4242
[target.'cfg(target_arch = "wasm32")'.dependencies]
43-
js-sys= "0.3.29"
44-
wasm-bindgen = "0.2.52"
43+
js-sys= "0.3.32"
44+
wasm-bindgen = "0.2.55"
4545

4646
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
47-
version = "0.3.29"
47+
version = "0.3.32"
4848
features = ['Document', 'DomRect', 'Element', 'HtmlElement', 'Node', 'Window', 'HtmlCanvasElement', 'CanvasRenderingContext2d']
4949

5050
[features]
@@ -73,15 +73,15 @@ point_series = []
7373

7474

7575
[dev-dependencies]
76-
rand = "^0.7.2"
77-
itertools = "^0.8.0"
76+
rand = "0.7.2"
77+
itertools = "0.8.2"
7878
rand_distr = "0.2.2"
7979
criterion = "0.3.0"
80-
rayon = "1.2.0"
80+
rayon = "1.2.1"
8181
rand_xorshift = "0.2.0"
8282

8383
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
84-
wasm-bindgen-test = "0.3.4"
84+
wasm-bindgen-test = "0.3.5"
8585

8686
[[bench]]
8787
name = "benchmark"

src/drawing/backend_impl/bitmap.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ impl<'a, P: PixelFormat> DrawingBackend for BitMapBackend<'a, P> {
912912
let alpha = style.as_color().alpha();
913913
let (r, g, b) = style.as_color().rgb();
914914

915-
if from.0 == to.0 || from.1 == to.1 {
915+
if (from.0 == to.0 || from.1 == to.1) && style.stroke_width() == 1 {
916916
if alpha >= 1.0 {
917917
if from.1 == to.1 {
918918
P::fill_rect_fast(self, from, to, r, g, b);
@@ -1317,6 +1317,22 @@ fn test_bitmap_bgrx_pixel_format() {
13171317
}
13181318
}
13191319
}
1320+
#[cfg(test)]
1321+
#[test]
1322+
fn test_draw_simple_lines() {
1323+
use crate::prelude::*;
1324+
let mut buffer = vec![0; 1000 * 1000 * 3];
1325+
1326+
{
1327+
let mut back = BitMapBackend::with_buffer(&mut buffer, (1000, 1000));
1328+
back.draw_line((500, 0), (500, 1000), &WHITE.filled().stroke_width(5))
1329+
.unwrap();
1330+
}
1331+
1332+
let nz_count = buffer.into_iter().filter(|x| *x != 0).count();
1333+
1334+
assert_eq!(nz_count, 6 * 1000 * 3);
1335+
}
13201336

13211337
#[cfg(test)]
13221338
#[test]

src/element/errorbar.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,31 @@ impl<K, V, O: ErrorBarOrient<K, V>, DB: DrawingBackend> Drawable<DB> for ErrorBa
117117
let points: Vec<_> = points.take(3).collect();
118118

119119
let (from, to) = O::ending_coord(points[0], self.width);
120-
backend.draw_line(from, to, &self.style.color)?;
120+
backend.draw_line(from, to, &self.style)?;
121121

122122
let (from, to) = O::ending_coord(points[2], self.width);
123-
backend.draw_line(from, to, &self.style.color)?;
123+
backend.draw_line(from, to, &self.style)?;
124124

125-
backend.draw_line(points[0], points[2], &self.style.color)?;
125+
backend.draw_line(points[0], points[2], &self.style)?;
126126

127-
backend.draw_circle(
128-
points[1],
129-
self.width / 2,
130-
&self.style.color,
131-
self.style.filled,
132-
)?;
127+
backend.draw_circle(points[1], self.width / 2, &self.style, self.style.filled)?;
133128

134129
Ok(())
135130
}
136131
}
132+
133+
#[cfg(test)]
134+
#[test]
135+
fn test_preserve_stroke_width() {
136+
let v = ErrorBar::new_vertical(100, 20, 50, 70, WHITE.filled().stroke_width(5), 3);
137+
let h = ErrorBar::new_horizontal(100, 20, 50, 70, WHITE.filled().stroke_width(5), 3);
138+
139+
use crate::prelude::*;
140+
let da = crate::create_mocked_drawing_area(300, 300, |m| {
141+
m.check_draw_line(|_, w, _, _| {
142+
assert_eq!(w, 5);
143+
});
144+
});
145+
da.draw(&h).expect("Drawing Failure");
146+
da.draw(&v).expect("Drawing Failure");
147+
}

0 commit comments

Comments
 (0)