plotters-rs / plotters

A rust drawing library for high quality data plotting for both WASM and native, statically and realtimely 🦀 📈🚀
https://plotters-rs.github.io/home/
MIT License
3.89k stars 281 forks source link

How to get pixel coord from Guest coordinate? #48

Closed serzhiio closed 5 years ago

serzhiio commented 5 years ago

Lets say i have chart with given coordinate system. I need to draw a dotted (horizontal) line through whole chart using one y-coord. And i want every dot to be 5px length. What is most efficient way?

38 commented 5 years ago

I guess this is what you are looking for. https://docs.rs/plotters/0.2.7/plotters/chart/struct.DualCoordChartContext.html#method.secondary_plotting_area

serzhiio commented 5 years ago

Why secondary? And how to extract pixel coordinates?

38 commented 5 years ago

Oh, I see, I misunderstood what you are trying to do. You should be able to strip the attached coordinate by using code like that.

chart.plotting_area().strip_coord_spec()

https://docs.rs/plotters/0.2.7/plotters/drawing/struct.DrawingArea.html#method.strip_coord_spec

serzhiio commented 5 years ago

Is it possible to draw series on the chart using pixel coordinates? I mean LineSeries?

38 commented 5 years ago

Not for now. But I think this may be something worth to add.

draw_series is almost the same as

series.for_each(|element| area.draw(element))

But if you want to add series annotation for series drawn in this way, it seems very tricky. But an API like draw_pixel_coord_series which provides ability for further annotation seems a nice idea.

I don't know if this is what you are asking for ?

serzhiio commented 5 years ago

Here is what i looked for: let (_, order_y) = price_chart.backend_coord(&(from, (max+min)/2.0));