tiby312 / poloto-project

MIT License
159 stars 10 forks source link

Add annotation API #198

Open tiby312 opened 1 year ago

tiby312 commented 1 year ago

Something like this:

use poloto::build;
// PIPE me to a file!
fn main() {
    let data = vec![[0, 0], [1, 2], [2, 3]];

    let a = build::plot("label").line(data);

    poloto::data(a)
        .build_and_label(("hello world", "x", "y"))
        .annotate(|w|{
            let point=w.convert_point([1,2]);

            let circle=hypermelon::build::elem("circle").with(attrs!(("x",point.x),("y",point.y)))

            let text_pos=w.request_text_position();

            let text=hypermelon::build::elem("text").with(attrs!(("x",text_pos.x),("y",text_pos.y)))

            circle.append(text)
        })
        .append_to(poloto::header().light_theme())
        .render_stdout();
}
tiby312 commented 1 year ago

Or at-least just provide a projection matrix that you can feed data points, and have the point in the svg canvas space.