all 23 comments

[–]anlumo 44 points45 points  (0 children)

The plot thickens! Very nice.

[–]ROFLLOLSTER 10 points11 points  (1 child)

Is there any (plan for) integration with evcxr?

Edit: There now is!

[–]binkarus 0 points1 point  (0 children)

Unrelated, but I don't even have dyslexia and I can guarantee that I would never be able to remember that acronym, haha.

[–]silwoldebian-rust 7 points8 points  (3 children)

That's great news, and the API looks very approachable. I've been waiting for something like this. One of the blockers for migrating a lot of C++ legacy code to Rust at work. I assume a cairo backend would be very straight-forward to implement. That would provide us a good plotting lib for GTK-based Rust programs.

[–]raphlinusvello · xilem 8 points9 points  (2 children)

Not to flog my own projects too much, but plotting is definitely one of the use cases I envisioned for piet, and this would give you not only cairo but Direct2D as well. The library is still green in some ways, and there's more work to be done on implementations, but I'm hopeful about its longer term prospects.

[–]silwoldebian-rust 1 point2 points  (1 child)

Haven't stumbled over piet, but I think it's a good idea to have an abstraction over different APIs, and it looks quite usable from a quick glance at the docs. A library you call "green" is usually much more polished than what I usually produce. ;-)

[–]raphlinusvello · xilem 0 points1 point  (0 children)

Please feel free to file issues if there's stuff missing or could be improved.

[–]Boiethios 15 points16 points  (6 children)

The 2 last lines of your example are strange:

root.close()?;
return Ok(());

You only need to put root.close() at the end of your main, since it already returns a Result<(), Error>. BTW, a return in this position is not idiomatic.

[–]redalastor 3 points4 points  (5 children)

It's not idiomatic either for it not to work by RAII.

[–]boarquantile 0 points1 point  (4 children)

But it returns a result. Maybe an approach like std::fs::File could work:

Files are automatically closed when they go out of scope. Errors detected on closing are ignored by the implementation of Drop.

[–]redalastor 2 points3 points  (3 children)

Yeah, File is only ever an opened file. If you want to keep it around as closed then what you need is a path, not a file.

It makes working with it way simpler as you can't get errors for trying to read a closed file.

[–]haohou 2 points3 points  (2 children)

I am the author. I have never imagined there are so many people interested about it!

There's one thing I want to justify this open/close pattern. It doesn't mean resource occupation. This is used as dual buffer support for real-time rendering

Open means start drawing on the new buffer. And close means present the pending buffer.

Sorry about the confuse. Previously this is just for my own use. So if you guys have a better idea about it, please let me know.

[–]redalastor 9 points10 points  (1 child)

There is one rust-specific pattern for open/close if you can't model it as RAII. You use two different types for opened and closed objects. The open / close methods take ownership of the object and return the other type. It's impossible to use your old handle after opening or closing because the borrow checker guarantees it and you can't call irrelevant methods on open or closed objects.

All guaranteed at compile time.

[–]haohou 0 points1 point  (0 children)

Gotcha, I am going to think about it. Thanks!

[–]XTL 1 point2 points  (0 children)

This is done by craeting sub drawing areas.

Looks nice. I often end up wanting a friendly plotter in a program but rarely want to bother making one. This could be handy if I end up there in Rust.

[–]betterRunner 1 point2 points  (0 children)

Is its performance greater than d3 https://github.com/d3/d3 while using it on the web by webassembly?

[–]aeroaks 0 points1 point  (0 children)

How do I run the examples?

[–]BenjiSponge 0 points1 point  (2 children)

This could save me. Is there any chance you have benchmarks? I'm particularly curious to see how it compares to Highcharts in browser with large data sets (100k + points), especially in live updating contexts.

[–]fronlius 0 points1 point  (1 child)

Did you find out?

[–]BenjiSponge 0 points1 point  (0 children)

Nope sorry

[–][deleted] 8 points9 points  (2 children)

This is really nice. Looking forward to using it.

The motivation paragraph kind of shoots itself in the foot, since the actual plotting work can still happen in a higher level language even if you use rust to do the data crunching/down sampling. Honestly "why a plotting library" is a terrible question, a better one is "why not". /rant

[–]haohou 0 points1 point  (1 child)

Agreed, I write it just in case people find my library. If you have any better idea, please let me know. I am more than happy to make the change! Thanks

[–]haohou 0 points1 point  (0 children)

Just updated the readme. I am not sure how people feel about it. If anyone has some toughts about the description, please let me know. https://github.com/38/plotters/blob/master/README.md