Skip to content

Commit

Permalink
Merge pull request #47 from lukstafi/main
Browse files Browse the repository at this point in the history
Fixes #24: representation extensions; provides a plotting extension: scatterplots, line plots, decision boundaries etc.
  • Loading branch information
c-cube authored Sep 30, 2024
2 parents d49d952 + 758efdd commit 540e3db
Show file tree
Hide file tree
Showing 27 changed files with 1,249 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ including:

See https://c-cube.github.io/printbox/

See the [test/](test/) and [examples/](examples/) directories for illustrations of potential usage.

## License

BSD-2-clauses
Expand Down
14 changes: 14 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@ Printbox allows to print nested boxes, lists, arrays, tables in several formats"
(printbox-html (and (= :version)))
(odoc :with-test)
(mdx (and (>= 1.4) :with-test))))

(package
(name printbox-ext-plot)
(synopsis "Printbox extension for plotting")
(description "
Extends Printbox with the ability to print scatter plots, line plots, decision boundaries.
Printbox allows to print nested boxes, lists, arrays, tables in several formats")
(depends (printbox (= :version))
(printbox-text (and (= :version)))
(printbox-html (and (= :version)))
(printbox-md (and (= :version)))
(tyxml (>= 4.3))
(odoc :with-test)
(mdx (and (>= 1.4) :with-test))))
39 changes: 39 additions & 0 deletions printbox-ext-plot.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.11"
synopsis: "Printbox extension for plotting"
description: """

Extends Printbox with the ability to print scatter plots, line plots, decision boundaries.
Printbox allows to print nested boxes, lists, arrays, tables in several formats"""
maintainer: ["c-cube" "lukstafi"]
authors: ["Simon Cruanes" "Guillaume Bury" "lukstafi"]
license: "BSD-2-Clause"
homepage: "https://github.com/c-cube/printbox"
bug-reports: "https://github.com/c-cube/printbox/issues"
depends: [
"dune" {>= "3.0"}
"printbox" {= version}
"printbox-text" {= version}
"printbox-html" {= version}
"printbox-md" {= version}
"tyxml" {>= "4.3"}
"odoc" {with-test}
"mdx" {>= "1.4" & with-test}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/c-cube/printbox.git"
8 changes: 8 additions & 0 deletions src/PrintBox.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module Style = struct
let fg_color c : t = set_fg_color c default
end

type ext = ..

type view =
| Empty
| Text of {
Expand All @@ -64,6 +66,10 @@ type view =
id: string;
inner: t;
}
| Ext of {
key: string;
ext: ext;
}

and t = view

Expand Down Expand Up @@ -203,6 +209,7 @@ let mk_tree ?indent f root =
let link ~uri inner : t = Link { uri; inner }
let anchor ~id inner : t = Anchor { id; inner }
let extension ~key ext = Ext { key; ext }
(** {2 Simple Structural Interface} *)
Expand All @@ -219,6 +226,7 @@ module Simple = struct
| `Table of t array array
| `Tree of t * t list
]
(** The simple interface does not support extensions. *)
let rec to_box = function
| `Empty -> empty
Expand Down
16 changes: 16 additions & 0 deletions src/PrintBox.mli
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ type t
(** Main type for a document composed of nested boxes.
@since 0.2 the type [t] is opaque *)

type ext = ..
(** Extensions of the representation.
@since NEXT_RELEASE
*)

(** The type [view] can be used to observe the inside of the box,
now that [t] is opaque.
Expand Down Expand Up @@ -137,6 +143,10 @@ type view = private
id: string;
inner: t;
}
| Ext of {
key: string;
ext: ext;
}

val view : t -> view
(** Observe the content of the box.
Expand Down Expand Up @@ -317,6 +327,12 @@ val anchor : id:string -> t -> t
@since 0.11
*)

val extension : key:string -> ext -> t
(** [extension ~key ext] embeds an extended representation [ext] as a box. [ext] must be
recognized by the used backends as an extension registered under [key].
@since NEXT_RELEASE
*)

(** {2 Styling combinators} *)

val line_with_style : Style.t -> string -> t
Expand Down
Loading

0 comments on commit 540e3db

Please sign in to comment.