// Requires Aner 0.0.10 or greater and PDF module 0.1.1 or greater.
// Install first: aner install pdf
// Synthetic observations for a reporting example, not a fitted model.
import aner.pdf
import aner.plot

let days = List(1.0, 2.0, 3.0, 4.0, 5.0)
let values = List(2.0, 2.7, 2.4, 3.3, 3.8)
let chart = plot.line(days, values)
    .title("Synthetic observations by day")
    .labels("Day", "Measured value (a.u.)")
    .caption("Five synthetic observations; no uncertainty estimates or fitted trend.")
    .theme(plot.theme("light"))
    .size(width: 640, height: 400)

let branding = pdf.template(header: "Analysis report", footer: "Page {page} of {pages}")
let report = pdf.document(title: "Measurements and figure", author: "Research team")
pdf.with_template(report, branding)
pdf.heading(report, "Measurements and figure")
pdf.text(report, "The figure below is captured directly from an immutable Aner Chart.")
pdf.plot(report, chart, width: 450.0, height: 280.0)
pdf.table(report, List("Day", "Measured value (a.u.)"),
    List(List("1", "2.0"), List("2", "2.7"), List("3", "2.4"),
         List("4", "3.3"), List("5", "3.8")))
let receipt = pdf.create("plot-report.pdf", report)
print(pdf.to_json(receipt))

// Read the saved PDF; chart labels remain selectable/extractable text.
let extracted = pdf.read("plot-report.pdf")
print(pdf.extract_text(extracted))
