-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f32249
commit cc063e7
Showing
9 changed files
with
333 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#import "/src/cetz.typ" as cetz | ||
#import "/src/lib.typ" as cetz-plot | ||
|
||
// String that gets prefixed to every example code | ||
// for compilation only! | ||
#let example-preamble = "import cetz.draw: *; import cetz-plot: *;" | ||
#let example-scope = (cetz: cetz, cetz-plot: cetz-plot) | ||
|
||
|
||
/// Render an example from a string | ||
/// - source (string, raw): Example source code | ||
/// - args (arguments): Arguments passed down to the canvas | ||
/// - vertical (boolean): If true, show the code below the canvas | ||
#let example(source, ..args, vertical: false) = { | ||
if type(source) == content { | ||
source = source.text | ||
} | ||
|
||
let radius = .25cm | ||
let border = 1pt + gray | ||
let canvas-background = yellow.lighten(95%) | ||
|
||
let picture = cetz.canvas( | ||
eval( | ||
example-preamble + source, | ||
scope: example-scope | ||
), | ||
..args | ||
) | ||
let source = box( | ||
raw( | ||
source, | ||
lang: "typc" | ||
), | ||
width: 100% | ||
) | ||
|
||
block( | ||
if vertical { | ||
align( | ||
center, | ||
stack( | ||
dir: ttb, | ||
spacing: 1em, | ||
block( | ||
width: 100%, | ||
clip: true, | ||
radius: radius, | ||
stroke: border, | ||
table( | ||
columns: 1, | ||
stroke: none, | ||
fill: (c,r) => (canvas-background, white).at(r), | ||
picture, | ||
align(left, source) | ||
) | ||
), | ||
) | ||
) | ||
} else { | ||
block( | ||
table( | ||
columns: 2, | ||
stroke: none, | ||
fill: (canvas-background, white), | ||
align: (center + horizon, left), | ||
picture, | ||
source | ||
), | ||
width: 100%, | ||
radius: radius, | ||
clip: true, | ||
stroke: border | ||
) | ||
}, breakable: false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#import "example.typ": example | ||
#import "/src/lib.typ" | ||
|
||
#import "@preview/tidy:0.1.0" | ||
#import "@preview/t4t:0.3.2": is | ||
|
||
#let show-function(fn, style-args) = { | ||
[ | ||
#heading(fn.name, level: style-args.first-heading-level + 1) | ||
#label(style-args.label-prefix + fn.name + "()") | ||
] | ||
let description = if is.sequence(fn.description) { | ||
fn.description.children | ||
} else { | ||
(fn.description,) | ||
} | ||
let parameter-index = description.position(e => { | ||
e.func() == heading and e.body == [parameters] | ||
}) | ||
|
||
description = description.map(e => if e.func() == heading { | ||
let fields = e.fields() | ||
let label = fields.remove("label", default: none) | ||
heading(offset: style-args.first-heading-level + 1, fields.remove("body"), ..fields); [#label] | ||
} else { e }) | ||
|
||
if parameter-index != none { | ||
description.slice(0, parameter-index).join() | ||
} else { | ||
description.join() | ||
} | ||
|
||
set heading(level: style-args.first-heading-level + 2) | ||
|
||
block(breakable: style-args.break-param-descriptions, { | ||
heading("Parameters", level: style-args.first-heading-level + 2) | ||
(style-args.style.show-parameter-list)(fn, style-args.style.show-type) | ||
}) | ||
|
||
for (name, info) in fn.args { | ||
let types = info.at("types", default: ()) | ||
let description = info.at("description", default: "") | ||
if description == [] and style-args.omit-empty-param-descriptions { continue } | ||
(style-args.style.show-parameter-block)( | ||
name, types, description, | ||
style-args, | ||
show-default: "default" in info, | ||
default: info.at("default", default: none), | ||
) | ||
} | ||
|
||
if parameter-index != none { | ||
description.slice(parameter-index+1).join() | ||
} | ||
} | ||
|
||
#let show-parameter-block(name, types, content, show-default: true, default: none, in-tidy: false, ..a) = { | ||
if type(types) != array { | ||
types = (types,) | ||
} | ||
stack(dir: ttb, spacing: 1em, | ||
// name <type> Default: <default> | ||
block(breakable: false, width: 100%, stack(dir: ltr, | ||
[#text(weight: "bold", name + [:]) #types.map(tidy.styles.default.show-type).join(" or ")], | ||
if show-default { | ||
align(right)[ | ||
Default: #raw( | ||
lang: "typc", | ||
// Tidy gives defaults as strings but outside of tidy we pass defaults as the actual values | ||
if in-tidy { default } else { repr(default) } | ||
) | ||
] | ||
} | ||
)), | ||
// text | ||
block(inset: (left: .4cm), content) | ||
) | ||
} | ||
|
||
|
||
#let show-type = tidy.styles.default.show-type | ||
#let show-outline = tidy.styles.default.show-outline | ||
#let show-parameter-list = tidy.styles.default.show-parameter-list | ||
|
||
#let style = ( | ||
show-function: show-function, | ||
show-parameter-block: show-parameter-block.with(in-tidy: true), | ||
show-type: show-type, | ||
show-outline: show-outline, | ||
show-parameter-list: show-parameter-list | ||
) | ||
|
||
#let parse-show-module(path) = { | ||
tidy.show-module( | ||
tidy.parse-module( | ||
read(path), | ||
scope: ( | ||
example: example, | ||
show-parameter-block: show-parameter-block, | ||
cetz: lib | ||
) | ||
), | ||
show-outline: false, | ||
sort-functions: none, | ||
style: style | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#import "/src/lib.typ" as cetz-plot | ||
|
||
/// Make the title-page | ||
#let make-title() = { | ||
let left-fringe = 39% | ||
let left-color = rgb(140,90,255).darken(30%) | ||
let right-color = white | ||
|
||
let url = "https://github.com/cetz-package/cetz-plot" | ||
let authors = ( | ||
([Johannes Wolf], "https://github.com/johannes-wolf"), | ||
([fenjalien], "https://github.com/fenjalien"), | ||
) | ||
|
||
set page( | ||
numbering: none, | ||
background: place( | ||
top + left, | ||
rect( | ||
width: left-fringe, | ||
height: 100%, | ||
fill: left-color | ||
) | ||
), | ||
margin: ( | ||
left: left-fringe * 22cm, | ||
top: 12% * 29cm | ||
), | ||
header: none, | ||
footer: none | ||
) | ||
|
||
set text(weight: "bold", left-color) | ||
show link: set text(left-color) | ||
|
||
block( | ||
place( | ||
top + left, | ||
dx: -left-fringe * 22cm + 5mm, | ||
text(3cm, right-color)[CeTZ] | ||
) + | ||
text(3cm)[Plot] | ||
) | ||
block( | ||
v(1cm) + | ||
text( | ||
20pt, | ||
authors.map(v => link(v.at(1), [#v.at(0)])).join("\n") | ||
) | ||
) | ||
block( | ||
v(2cm) + | ||
text( | ||
20pt, | ||
link( | ||
url, | ||
[Version ] + [#cetz-plot.version] | ||
) | ||
) | ||
) | ||
pagebreak(weak: true) | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
TODO | ||
#import "/doc/util.typ": * | ||
#import "/doc/example.typ": example | ||
#import "/doc/style.typ" as doc-style | ||
#import "/src/lib.typ": * | ||
#import "/src/cetz.typ": * | ||
#import "@preview/tidy:0.2.0" | ||
|
||
|
||
// Usage: | ||
// ```example | ||
// /* canvas drawing code */ | ||
// ``` | ||
#show raw.where(lang: "example"): example | ||
#show raw.where(lang: "example-vertical"): example.with(vertical: true) | ||
|
||
#make-title() | ||
|
||
#set terms(indent: 1em) | ||
#set par(justify: true) | ||
#set heading(numbering: (..num) => if num.pos().len() < 4 { | ||
numbering("1.1", ..num) | ||
}) | ||
#show link: set text(blue) | ||
|
||
// Outline | ||
#{ | ||
show heading: none | ||
columns(2, outline(indent: true, depth: 3)) | ||
pagebreak(weak: true) | ||
} | ||
|
||
#set page(numbering: "1/1", header: align(right)[CeTZ-Plot]) | ||
|
||
= Plot | ||
|
||
#doc-style.parse-show-module("/src/plot.typ") | ||
#for m in ("line", "bar", "boxwhisker", "contour", "errorbar", "annotation", "formats") { | ||
doc-style.parse-show-module("/src/plot/" + m + ".typ") | ||
} | ||
|
||
= Chart | ||
|
||
#doc-style.parse-show-module("/src/chart.typ") | ||
#for m in ("barchart", "boxwhisker", "columnchart", "piechart") { | ||
doc-style.parse-show-module("/src/chart/" + m + ".typ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.