Skip to content

Fix pistons scaling of circles #148

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jun 29, 2020
Merged

Fix pistons scaling of circles #148

merged 2 commits into from
Jun 29, 2020

Conversation

pelekhay
Copy link
Contributor

issue can be easily reproduced by modifying piston-demo example.

diff --git a/examples/piston-demo/src/main.rs b/examples/piston-demo/src/main.rs
index b58a100..307d71c 100644
--- a/examples/piston-demo/src/main.rs
+++ b/examples/piston-demo/src/main.rs
@@ -58,7 +58,7 @@ fn main() {
             cc.draw_series(LineSeries::new(
                 (0..).zip(data.iter()).map(|(a, b)| (a, *b)),
                 &Palette99::pick(idx),
-            ))?
+            ).point_size(4))?
             .label(format!("CPU {}", idx))
             .legend(move |(x, y)| {
                 Rectangle::new([(x - 5, y - 5), (x + 5, y + 5)], &Palette99::pick(idx))

actual result looks like:
image
expected result is something like:
image

@codecov
Copy link

codecov bot commented Jun 1, 2020

Codecov Report

Merging #148 into master will increase coverage by 0.06%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #148      +/-   ##
==========================================
+ Coverage   67.48%   67.54%   +0.06%     
==========================================
  Files          53       53              
  Lines        5160     5167       +7     
==========================================
+ Hits         3482     3490       +8     
+ Misses       1678     1677       -1     
Impacted Files Coverage Δ
src/drawing/backend_impl/piston.rs 7.69% <87.50%> (+7.69%) ⬆️
src/drawing/backend_impl/svg.rs 75.78% <0.00%> (+0.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dee7727...5244a9f. Read the comment docs.

@38 38 merged commit 4c63766 into plotters-rs:master Jun 29, 2020
@38
Copy link
Member

38 commented Jun 29, 2020

Thanks!

@pelekhay
Copy link
Contributor Author

welcome :)

@nabajour
Copy link

nabajour commented Nov 4, 2020

Is this fixed in the released version?
I'm just starting to learn rust and try to find a way to display a graph. I ran into issues having my circles that do not align with the edges in my graph. I think I still run into this issue with plotters="0.3.0" or I'm doing something wrong with my setup or with my cartesian coordinates.

Here is an example. The circles fall beside the edges. I think it's specific to Circle. Replacing Circle by Cross gives me aligned crosses. Doing the output in a png gets the circles aligned.

use piston_window::{EventLoop, PistonWindow, WindowSettings};
use plotters::prelude::*;
use plotters_piston::{draw_piston_window, PistonBackend};

use plotters::coord::types::*;

fn main() {
    let mut window: PistonWindow = WindowSettings::new("Display", [640, 480])
       .samples(4)
       .build()
       .unwrap();

    while let Some(_) = draw_piston_window(&mut window, |b| {

    let root = b.into_drawing_area();

    root.fill(&WHITE).unwrap();

    let root2 = root.apply_coord_spec(Cartesian2d::<RangedCoordf32, RangedCoordf32>::new(
            0f32..1f32,
            0f32..1f32,
            (0..640, 0..480),
    ));
   
    let coords = [(0.5, 0.5), (0.25, 0.75), (0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0,0.0)];	

        let dot_and_label = |x: f32, y: f32| {
            return EmptyElement::at((x, y))
                  + Circle::new((0, 0), 3, ShapeStyle::from(&BLACK).filled());
        };

    for c in coords.iter() {
        root2.draw(&dot_and_label(c.0, c.1)    );
    }

    root2.draw(&PathElement::new(coords, Into::<ShapeStyle>::into(&RED).filled()));

    Ok(())
    }) {}    
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants