diff --git a/docs/printbox-ext-plot-example_Map.png b/docs/printbox-ext-plot-example_Map.png new file mode 100644 index 0000000..aa2c364 Binary files /dev/null and b/docs/printbox-ext-plot-example_Map.png differ diff --git a/docs/printbox-ext-plot-example_half_moons.png b/docs/printbox-ext-plot-example_half_moons.png new file mode 100644 index 0000000..928e419 Binary files /dev/null and b/docs/printbox-ext-plot-example_half_moons.png differ diff --git a/docs/printbox-ext-plot-example_linear.png b/docs/printbox-ext-plot-example_linear.png new file mode 100644 index 0000000..5e3ac7b Binary files /dev/null and b/docs/printbox-ext-plot-example_linear.png differ diff --git a/docs/printbox-ext-plot-example_nested.png b/docs/printbox-ext-plot-example_nested.png new file mode 100644 index 0000000..2fe98f1 Binary files /dev/null and b/docs/printbox-ext-plot-example_nested.png differ diff --git a/dune-project b/dune-project index 020d80a..9e62143 100644 --- a/dune-project +++ b/dune-project @@ -31,7 +31,6 @@ Adds html output handling to the printbox package. Printbox allows to print nested boxes, lists, arrays, tables in several formats") (depends (printbox (= :version)) - (printbox-text (and (= :version) :with-test)) (odoc :with-test) (tyxml (>= 4.3)) (mdx (and (>= 1.4) :with-test)))) @@ -44,7 +43,6 @@ Adds Markdown output handling to the printbox package, with fallback to text and Printbox allows to print nested boxes, lists, arrays, tables in several formats") (depends (printbox (= :version)) (printbox-text (and (= :version))) - (printbox-html (and (= :version))) (odoc :with-test) (mdx (and (>= 1.4) :with-test)))) diff --git a/printbox-html.opam b/printbox-html.opam index f928763..08d4464 100644 --- a/printbox-html.opam +++ b/printbox-html.opam @@ -14,7 +14,6 @@ bug-reports: "https://github.com/c-cube/printbox/issues" depends: [ "dune" {>= "3.0"} "printbox" {= version} - "printbox-text" {= version & with-test} "odoc" {with-test} "tyxml" {>= "4.3"} "mdx" {>= "1.4" & with-test} diff --git a/printbox-md.opam b/printbox-md.opam index 0727a85..123136b 100644 --- a/printbox-md.opam +++ b/printbox-md.opam @@ -15,7 +15,6 @@ depends: [ "dune" {>= "3.0"} "printbox" {= version} "printbox-text" {= version} - "printbox-html" {= version} "odoc" {with-test} "mdx" {>= "1.4" & with-test} "odoc" {with-doc} diff --git a/src/printbox-ext-plot/README.md b/src/printbox-ext-plot/README.md new file mode 100644 index 0000000..c6c8042 --- /dev/null +++ b/src/printbox-ext-plot/README.md @@ -0,0 +1,290 @@ +# PrintBox extension for rendering plots over a 2D canvas + +See https://ocaml.org/p/printbox-ext-plot/latest/doc/PrintBox_ext_plot/index.html ([source](PrintBox_ext_plot.mli)). + +## Example: Map, Scatterbag + +[Source.](../../test/plotting.ml) + +The `specs` of this graph: + +```ocaml +Scatterbag + { points = [| ((0., 1.), B.line "Y"); ((1., 0.), B.line "X"); ((0.75, 0.75), B.line "M") |] }; +Map { callback = (fun (x, y) -> + let s = ((x ** 2.) +. (y ** 2.)) ** 0.5 in + B.line @@ + if s < 0.3 then " " + else if s < 0.6 then "." + else if s < 0.9 then "," + else if s < 1.2 then ":" + else ";"); } +``` + +Text rendering: + +```verbatim +┌──┬────────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ 1│Y:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;│ +│ │::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;│ +│ │:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;;;;;;;;;;│ +│ │::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;;;;;;;│ +│ │,,,,,,,::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;;;;│ +│ │,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;│ +│ │,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;│ +│ │,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;│ +│ │,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;│ +│ │,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::::::::::::::::::::::::::::::;;;;;;;;│ +│ │,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::::::::M:::::::::::::::::::;;;;;;│ +│ │,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::::::::::::::::::::::::::;;;;│ +│ │,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::::::::::::::::::::::::::;;│ +│ │,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::::::::::::::::::::::::;│ +│ │,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::::::::::::::::::::::│ +│ │,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::::::::::::::::::│ +│ │...........,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::::::::::::::::│ +│ │.....................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::::::::::::::│ +│ │...........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::::::::::::│ +│y │...............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::::::::::│ +│ │...................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::::::::::│ +│ │......................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::::::::│ +│ │.........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::::::│ +│ │............................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::::│ +│ │..............................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::::│ +│ │................................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::::│ +│ │..................................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::::│ +│ │...................................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::::│ +│ │ ..........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::│ +│ │ ......................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::::│ +│ │ ....................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::│ +│ │ ..................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::│ +│ │ .................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::│ +│ │ ................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::::│ +│ │ ................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::│ +│ │ ...............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::│ +│ │ ..............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::│ +│ │ ..............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::│ +│ │ ..............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::::::::│ +│ 0│ ..............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::X│ +├──┼────────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ │0 1│ +│ │ x │ +└──┴────────────────────────────────────────────────────────────────────────────────────────────────────┘ +``` + +HTML rendering image: +![A plot as above rendered with a white background](../../docs/printbox-ext-plot-example_Map.png) + +## Example: Line_plot_adaptive, Boundary_map + +[Source.](../../test/plotting_linear.ml) + +The `specs` of this graph: + +```ocaml +Line_plot_adaptive + { callback = (fun x -> sin x); content = B.line "#"; cache = Hashtbl.create 20 }; +Line_plot_adaptive + { callback = (fun x -> x ** 2.); content = B.line "%"; cache = Hashtbl.create 20 }; +Boundary_map + { content_false = B.line "."; content_true = B.line ","; callback = (fun (x, y) -> x > y) } +``` + +Text rendering: + +```verbatim +┌──┬────────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ 1│...................................................................................................%│ +│ │.................................................................................................,%,│ +│ │..............................................................................................,,,%,,│ +│ │............................................................................................,,,,%,,,│ +│ │.........................................................................................,,,,,%%,,,,│ +│ │.......................................................................................,,,,,,%,,,,,,│ +│ │....................................................................................,,,,,,,,%,,,,,,,│ +│ │..................................................................................,,,,,,,,%%,,,,####│ +│ │...............................................................................,,,,,,,,,,%,#####,,,,│ +│ │.............................................................................,,,,,,,,,,####,,,,,,,,,│ +│ │..........................................................................,,,,,,,,,,###,,,,,,,,,,,,,│ +│ │........................................................................,,,,,,,,####%%,,,,,,,,,,,,,,│ +│ │.....................................................................,,,,,,,####,,,%,,,,,,,,,,,,,,,,│ +│ │...................................................................,,,,,,###,,,,,%%,,,,,,,,,,,,,,,,,│ +│ │................................................................,,,,,####,,,,,,,%,,,,,,,,,,,,,,,,,,,│ +│ │.............................................................,,,,,###,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,│ +│ │...........................................................,,,,###,,,,,,,,,,,%,,,,,,,,,,,,,,,,,,,,,,│ +│ │........................................................,,,,###,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,│ +│ │......................................................,,,###,,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,│ +│y │...................................................,,,###,,,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.................................................,,###,,,,,,,,,,,,,,,,%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │..............................................,,###,,,,,,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │............................................,###,,,,,,,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.........................................,###,,,,,,,,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.......................................,##,,,,,,,,,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │....................................,###,,,,,,,,,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │..................................###,,,,,,,,,,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │...............................###,,,,,,,,,,,,,,,,,,,,,%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │............................,##,,,,,,,,,,,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │..........................###,,,,,,,,,,,,,,,,,,,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.......................,##,,,,,,,,,,,,,,,,,,,,,,%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.....................###,,,,,,,,,,,,,,,,,,,,,%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │..................###,,,,,,,,,,,,,,,,,,,,,%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │................##,,,,,,,,,,,,,,,,,,,,,%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.............###,,,,,,,,,,,,,,,,,,,,%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │...........##,,,,,,,,,,,,,,,,,,,%%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │........###,,,,,,,,,,,,,,,,,%%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │......##,,,,,,,,,,,,,,,%%%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │...###,,,,,,,,,,%%%%%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ 0│###%%%%%%%%%%%%%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +├──┼────────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ │0 1│ +│ │ x │ +└──┴────────────────────────────────────────────────────────────────────────────────────────────────────┘ +``` + +HTML rendering image: +![A plot as above rendered with a white background](../../docs/printbox-ext-plot-example_linear.png) + +### Example: nested boxes + +[Source.](../../test/plotting_nested.ml) + +The `specs` of this graph: + +```ocaml +Scatterbag { points = [| ((0.06, 0.95), reg_45); ((0.3, 0.3), reg_45) |] }; +Scatterbag { + points = [| + ((0., 1.), nice_unicode); + ((0.08, 0.9), nice_unicode); + ((1., 0.), for_3); + ((0.3, 0.3), nice_unicode); + ((0.75, 0.75), nice_unicode); + ((0.8, 0.8), nice_unicode); |]; }; +Map { + callback = (fun (x, y) -> + let s = ((x ** 2.) +. (y ** 2.)) ** 0.5 in + B.line + @@ + if s < 0.3 then " " + else if s < 0.6 then "." + else if s < 0.9 then "," + else if s < 1.2 then ":" + else ";"); } +``` + +Text rendering: + +```verbatim +┌──┬─────────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ 1│┌────────────────────────────────────┐::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; │ +│ ││nice unicode! 💪 │:::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;│ +│ │├────┌─────────┐─────────────────────┤:::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;;;;;;;;;; │ +│ ││┌───│123456789│┬───────────────────┐│::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;;;;;;; │ +│ │││oï ├─────────┤────────────────────────────┐::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;;;; │ +│ │││π/2│┌───────┐│code! 💪 │::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;;;;;│ +│ │││τ/4││ ....││────────────────────────────┤::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;;;; │ +│ ││├───│├───────┤│───────┬───────────────────┐│::::::::::::::::::::::::::::::::::::::::::;;;;;;;;;;;;; │ +│ │││ ││. ││d nums:│┌─────────────────┐││::::::::::::::::::::::::::::::::::┌──────────────────── │ +│ │││ │└───────┘│ ││┌───────────────┐│││,,::::::::::::::::::::::::::::::::│nice unicode! 💪 │ +│ │││ └─────────┘ │││┌─────────────┐││││,,,,,,:::::::::::::::::::::::┌───────────────────────── │ +│ │││ ├─│├──────────────┤│││sum=Σ_i a·xᵢ²│││││,,,,,,,,,::::::::::::::::::::│nice unicode! 💪 │ +│ │││ └─││ ││││————— │││││,,,,,,,,,,,,:::::::::::::::::├───────────────────────── │ +│ │││ ││ ││││1+1 │││││,,,,,,,,,,,,,,,::::::::::::::│┌──────────────┬───────── │ +│ │││ ││ 0 │││├─────────────┤││││,,,,,,,,,,,,,,,,,,:::::::::::││oï ωεird nums:│┌──────── │ +│ │││ ││ ├─1 ││││ Ōₒ│││││,,,,,,,,,,,,,,,,,,,,,::::::::││π/2 ││┌─────── │ +│ ││└─────││ └─ω ││││ À │││││,,,,,,,,,,,,,,,,,,,,,,,::::::││τ/4 │││┌────── │ +│ │└──────││ └─ω² │││└─────────────┘││││,,,,,,,,,,,,,,,,,,,,,,,,,::::│├──────────────┤│││sum=Σ_ │ +│ │.......││ ││└───────────────┘│││,,,,,,,,,,,,,,,,,,,,,,,,,,,::││ ││││————— │ +│y │.......││ │└─────────────────┘││,,,,,,,,,,,,,,,,,,,,,,,,,,,,,││ ││││1+1 │ +│ │.......│└──────────────┴───────────────────┘│,,,,,,,,,,,,,,,,,,,,,,,,,,,,,││ 0 │││├────── │ +│ │.......└────────────────────────────────────┘,,,,,,,,,,,,,,,,,,,,,,,,,,,,,││ ├─1 ││││ │ +│ │.........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,││ └─ω ││││ │ +│ │............................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,││ └─ω² │││└────── │ +│ │..............................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,││ ││└─────── │ +│ │................................................,,,,,,,,,,,,,,,,,,,,,,,,,,││ │└──────── │ +│ │..................................................,,,,,,,,,,,,,,,,,,,,,,,,│└──────────────┴───────── │ +│ │...................................................,,,,,,,,,,,,,,,,,,,,,,,└───────────────────────── │ +│ │ ..................┌─────────┐──────────────────────────┐,,,,,,,,,,,,,,,,,,::::::::::::::: │ +│ │ .............│123456789│de! 💪 │,,,,,,,,,,,,,,,,,,,,::::::::::::::│ +│ │ ..........├─────────┤──────────────────────────┤,,,,,,,,,,,,,,,,,,,,::::::::::::: │ +│ │ .......│┌───────┐│─────┬───────────────────┐│,,,,,,,,,,,,,,,,,,,,::::::::::::: │ +│ │ .....││ ....││nums:│┌─────────────────┐││,,,,,,,,,,,,,,,,,,,,,:::::::::::: │ +│ │ ...│├───────┤│ ││┌───────────────┐│││,,,,,,,,,,,,,,,,,,,,,:::::::::::: │ +│ │ ..││. ││ │││┌─────────────┐││││,,,,,,,,,,,,,,,,,,,,,,::::::::::: │ +│ │ .│└───────┘│─────┤│││sum=Σ_i a·xᵢ²│││││,,,,,,,,,,,,,,,,,,,,,,::::::::::: │ +│ │ └─────────┘ ││││————— │││││,,,,,,,,,,,,,,,,,,,,,,::::::::::: │ +│ │ ││ ││││1+1 │││││,,,,,,,,,,,,,,,,,,,,,,::::::::::: │ +│ │ ││ 0 │││├─────────────┤││││,,,,,,,,,,,,,,,,,,,,,,,:::::::::: │ +│ 0│ ││ ├─1 ││││ Ōₒ│││││,,,,,,,,,,,,,,,,,,,,,,,:::::::::( │ +├──┼─────────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ │0 1│ +│ │ x │ +└──┴─────────────────────────────────────────────────────────────────────────────────────────────────────┘ +``` + +HTML rendering image: +![A plot as above rendered with a white background](../../docs/printbox-ext-plot-example_nested.png) + +## Example: Scatterplot + +[Source.](../../test/plotting_nested.ml) + +The `specs` of this graph: + +```ocaml +Scatterplot { points = points1; content = B.line "#" }; +Scatterplot { points = points2; content = B.line "%" }; +Boundary_map { content_false = B.line "."; content_true = B.line ","; + callback = fun (x, y) -> x > y } +``` + +Text rendering: + +```verbatim +┌───────┬────────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ 1.09 │............................#.........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.............................##.#...##..##..........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │......................########.###..#.....#.##.....................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.....................#.#..####.#...#.#..##.#...#.....#...........,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │..............#....##########.##....####.#...#.##.#.............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.............#.#####.###.#.#.#.##....###..##.##..##............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.................#.#.#####.###...####..#..#.##.#.##.##.......,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.........#....##..##.#..#..####.###......###..##.####.##.##.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.........#.....#...###.##.##...#.#.#.#...#.....#.##.#####.,,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │..........###....#.#####.##.#..........#..#.....#####..###,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.......#..#.#..#.#....#.....#................#..##...#.#,,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │......###.###..##.##..........................#....#..###,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │...#....#.###.##.##..........%.....................##,,#,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │......#######....#...................%%..........#.,,##,#,###,,,,,,,,,,,,,,,,,,,,,,,,,,,,%,,,,,%,,,,│ +│ │.##.##...##.#...##...............%...%............,,,,##,##,###,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ │.#.#.#.###.##.##.................%%...%.........,,,,,,,,###,,,##,,#,,,,,,,,,,,,,,,,,,,,,,,,,%%%,%%,,│ +│ │.....#.#..##...................%..%%%%%........,,,,,,,,,###,###,#,,,,,,,,,,,,,,,,,,,,,,,%%,,,%%%%,,,│ +│ │#.##.###.#.#................%.%...%.%%%......,,,,,,,,,#,,,#,,,,#,,#,,,,,,,,,,,,,,,,,,,,%,,,%,,%,,,,,│ +│ │#####.#...##.................%..%.%.....%...,,,,,,,,,,,,,#,,##,###,##,,,,,,,,,,,,,,,,,%%%,,,,%%,%,%,│ +│y │#.#.###.#.##.................%%.%.%%%..%...,,,,,,,,,,,,#,,,,,,,#,#,#,,,,,,,,,,,,,,,,,,%%,%,,,,,,%,%%│ +│ │##...###..#..................%%..%..%.%..,,,,,,,,,,,,,,,,##,,####,,,,#,,,,,,,,,,,,,,,%,,%,,,%,%,,%%,│ +│ │##......###..........................%%.%,%,,,,,,,,,,,,,,,,,,,,#,####,,,,,,,,,,,,,,,,,,,%%,,,,,%,%%,│ +│ │...#.#.###...................%..%%%%..%,,%,,,,,,,,,,,,,,,,##,,#######,,,,,,,,,,,,,,,,%%%,,,,,%,%,,,,│ +│ │......##.......................%...%.%%%,,,,,,,,,,,,,,,,,#,#,#,,,,,,#,,,,,,,,,,,,,,,,,,%,,%%,,,%%%,,│ +│ │....#..#...........................%,%,,%,,%,,,,,,,,,,,,,,,,#,,,,,,#,,,,,,,,,,,,,,,%,%%%%,,%%,,%,,,,│ +│ │........##.......................%,%%,,,%,%,,,,,,,,,,,,,,,,,,,#,,##,,,,,,,,,,,,,,,%%,,,%,,%%%,%,,,,,│ +│ │#.#............................%.,%,,%,,%%,,,,%%,,,,,,,,,#,,#,,,,,#,#,,,,,,,,,,,,,,,,%%%,%%,,,,,,,,,│ +│ │.#...#.........................,%%%,,%%%%%,%,,,,,,,,,,,,,,,,,#,,,,#,,,,,,,,,,%,,,,,%%%%,%,%,,,%,,,,,│ +│ │..............................,,,,,,,%,,%%%,,,%,%%%,%,,,,#,,,,,,,,,,,,,,,,,,,,%,%,,%,%%,%,%%,,%,,,,,│ +│ │............................,,,,,,%,%%%%%,%,%,%,%,,,,,,%,,,,,,,,,,,,,,,,,,,,,,%%,,%%,%,%,%,,,,%,,,,,│ +│ │...........................,,,,,,,,%,,,%%%%%,%%%,,,,,,,%,,,,,,,,,,,,,,,,%,%%,,%,%%%%%,%%,,,,,,,,,,,,│ +│ │.........................,,,,,,,,,,,,,,,,%,,,,,%%%%%,%,%,%%,,,,,,,,,,%,%%%%%%,%,,%,,,,,,,,,,,,,,,,,,│ +│ │........................,,,,,,,,,,,,%,,,%,%%,%,,,,,,,%,,%%,,%%,%,,,%%%%%%%,,%,%,%,,,,,%%,,,,,,,,,,,,│ +│ │.......................,,,,,,,,,,,,,,,%,,%,%%,%%%,,,,%,%%%,%%,,,%,%%,%,%,%%%,,%%%%%,,,,,,%,,,,,,,,,,│ +│ │.....................,,,,,,,,,,,,,,,,,,%%%%,%,,%,,,,,,,%%%,,%,,%%%%,%%,,,%,%,,%%,,%,,,,,,,,,,,,,,,,,│ +│ │....................,,,,,,,,,,,,,,,,,,,,,,,,,%,,%%,,%,%,%,%%,%%,,,%,,,%,%%,,,%%%,,,%%%,,,,,,,,,,,,,,│ +│ │..................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%,,%%%,,%%%%,,%%%%,,,%%,%%%%%,,,,,,%,,,,,,,,,,,,,,│ +│ │.................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%%%,,,,,,,,%%%%%%,%%,%,,%%,%,,,,%,,,,,,,,,,,,,,,,,,,│ +│ │...............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%,%%,%%%,%%%,,%%%%,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,,│ +│ -0.794│..............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,%,,,,,,%,,,,,%,,,%,,,,%%,,,,,,,,,,,,,,,,,,,,,,,,,│ +├───────┼────────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ │-1.25 2.1│ +│ │ x │ +└───────┴────────────────────────────────────────────────────────────────────────────────────────────────────┘ +``` + +HTML rendering image: +![A plot as above rendered with a white background](../../docs/printbox-ext-plot-example_half_moons.png) diff --git a/src/printbox-md/PrintBox_md.ml b/src/printbox-md/PrintBox_md.ml index 99f0b16..4a2a365 100644 --- a/src/printbox-md/PrintBox_md.ml +++ b/src/printbox-md/PrintBox_md.ml @@ -8,7 +8,6 @@ module Config = struct | Code_quote type t = { - tables: [ `Text | `Html ]; vlists: [ `Line_break | `List | `As_table ]; hlists: [ `Minimal | `As_table ]; foldable_trees: bool; @@ -20,7 +19,6 @@ module Config = struct let default = { - tables = `Text; vlists = `List; hlists = `Minimal; foldable_trees = false; @@ -32,7 +30,6 @@ module Config = struct let uniform = { - tables = `Html; vlists = `Line_break; hlists = `As_table; foldable_trees = true; @@ -42,8 +39,6 @@ module Config = struct tab_width = 4; } - let html_tables c = { c with tables = `Html } - let text_tables c = { c with tables = `Text } let vlists x c = { c with vlists = x } let hlists x c = { c with hlists = x } let foldable_trees c = { c with foldable_trees = true } @@ -386,16 +381,12 @@ let pp c out b = if code_block then fprintf out "@,%s```@,%s" prefix prefix; pp_print_string out sty_post | B.Frame { sub = fb; _ } -> - (match c.Config.frames, c.Config.tables, no_block with - | `As_table, `Html, _ -> - (* Don't indent in case there's an embedded multiline preformatted text. *) - PrintBox_html.pp ~flush:false ~indent:false () out b; - if not no_md then fprintf out "@,%s@,%s" prefix prefix - | `As_table, `Text, _ -> + (match c.Config.frames, no_block with + | `As_table, _ -> let style = B.Style.preformatted in let l = break_lines [ PrintBox_text.to_string_with ~style:false b ] in loop ~no_block ~no_md ~prefix (B.lines_with_style style l) - | _, _, true -> + | _, true -> (* E.g. in a first Markdown table cell, "> " would mess up rendering. *) fprintf out "[%a]" (fun _out -> loop ~no_block ~no_md ~prefix:(prefix ^ " ")) @@ -487,28 +478,10 @@ let pp c out b = row; if i < n_rows - 1 then fprintf out "@,%s" prefix) rows - | B.Grid (_, _) when c.Config.tables = `Html && String.length prefix = 0 -> - PrintBox_html.pp ~flush:false ~indent:(not no_block) () out b; - if not no_md then fprintf out "@,%s@,%s" prefix prefix | B.Grid (_, _) -> - (match c.Config.tables with - | `Text -> - let style = B.Style.preformatted in - let l = break_lines [ PrintBox_text.to_string_with ~style:false b ] in - loop ~no_block ~no_md ~prefix (B.lines_with_style style l) - | `Html -> - let table = - PrintBox_html.( - if no_block then - to_string - else - to_string_indent) - b - in - let lines = break_lines [ table ] in - pp_print_list - ~pp_sep:(fun out () -> if not no_block then fprintf out "@,%s" prefix) - pp_print_string out lines); + let style = B.Style.preformatted in + let l = break_lines [ PrintBox_text.to_string_with ~style:false b ] in + loop ~no_block ~no_md ~prefix (B.lines_with_style style l); if not no_md then fprintf out "@,%s@,%s" prefix prefix | B.Tree (_extra_indent, header, [||]) -> loop ~no_block ~no_md ~prefix header diff --git a/src/printbox-md/PrintBox_md.mli b/src/printbox-md/PrintBox_md.mli index 30f557a..71a61b2 100644 --- a/src/printbox-md/PrintBox_md.mli +++ b/src/printbox-md/PrintBox_md.mli @@ -23,12 +23,6 @@ module Config : sig val uniform : t (** The configuration that leads to more lightweight and uniform rendering. *) - val html_tables : t -> t - (** Output tables via {!PrintBox_html}. Already the case for the {!uniform} config. *) - - val text_tables : t -> t - (** Output tables via {!PrintBox_text}. Already the case for the {!default} config. *) - val vlists : [ `Line_break | `List | `As_table ] -> t -> t (** How to output {!PrintBox.vlist} boxes, i.e. single-column grids. - [`Line_break]: when the {!PrintBox.vlist} has bars, it puts a quoted horizontal rule diff --git a/src/printbox-md/README.md b/src/printbox-md/README.md index bde9aa1..cca8df0 100644 --- a/src/printbox-md/README.md +++ b/src/printbox-md/README.md @@ -32,25 +32,16 @@ The `` `Minimal `` style for horizontal boxes simply puts all entr or if \`Bars are set, | by the | vertical dash. -
It only works when all the elements fit |
- logically speaking, |
- on a single line. |
-
Otherwise, the fallback behavior is as if |
- `As_table |
- was used to configure horizontal boxes. |
-
Tables | that meet |
- neither |
- of: |
-
- Markdown's native | restrictions, | special cases: |
- hlist - vlist |
-
End up | as either |
- of the fallbacks: |
- printbox-text - printbox-html- |
-
a longiiish column 1 |
- a longiiish column 2 |
- a longiiish column 3 | a longiiish column 4 |
-
b longiiish column 1 |
- b longiiish column 2 |
- b longiiish column 3 |
- b longiiish column 4 |
-
c row 1 |
c row 2.1 c row 2.2 |
c row 3 |
header 5
subchild 5 - body 5 - subbody 5 - one tab end of sub 5 -end of 5
a | looooooooooooooooooooooooo oonng | ||||
bx |
| ||||
? |
|
header 1 | header 2 |
- header 3 |
-
cell 1.1 |
- cell 1.2 |
- cell 1.3 |
-
cell 2.1 |
- cell 2.2 | cell 2.3 |
-
header 1 | header 2 | header 3 |
cell 1.1 | cell 1.2 | cell 1.3 |
cell 2.1 | cell 2.2 | cell 2.3 |
┌────┐
│root│
└────┘
┌────┐
│root│
└────┘
a longiiish column 1 |
- a longiiish column 2 |
- a longiiish column 3 | a longiiish column 4 |
-
b longiiish column 1 |
- b longiiish column 2 |
- b longiiish column 3 |
- b longiiish column 4 |
-
c row 1 |
c row 2.1 c row 2.2 |
c row 3 |
header 5
subchild 5 - body 5 - subbody 5 - one tab end of sub 5 -end of 5
a | looooooooooooooooooooooooo oonng | ||||
bx |
| ||||
? |
|
header 1 | header 2 |
- header 3 |
-
cell 1.1 |
- cell 1.2 |
- cell 1.3 |
-
cell 2.1 |
- cell 2.2 | cell 2.3 |
-
header 1 | header 2 | header 3 |
cell 1.1 | cell 1.2 | cell 1.3 |
cell 2.1 | cell 2.2 | cell 2.3 |
┌────┐
│root│
└────┘
┌────┐
│root│
└────┘