Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions plotst/axis.typ
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@

#let format(axis, value) = {
let fmt = axis.value_formatter
if type(fmt) == "string" {
if type(fmt) == str {
return strfmt(fmt, value)
} else if type(fmt) == "function" {
} else if type(fmt) == function {
return fmt(value)
}
}
Expand All @@ -108,7 +108,7 @@
// returns the expected need of space as a (width, height) array
// axis: the axis
// style: styling
#let measure_axis(axis, style) = {
#let measure_axis(axis) = {
let invert_markings = 1
if axis.location == "right" {
invert_markings = -1
Expand Down Expand Up @@ -177,7 +177,7 @@
// Places the title
//place(dy: -50%, rotate(-90deg, axis.title)) // TODO
context {
let a = measure_axis(axis, style).at(0)
let a = measure_axis(axis).at(0)
if axis.location == "left" {
place(dy: pos.at(1) - length / 2, dx: -length/2 - a, rotate(-90deg, origin: center + top, box(width: length, height:0pt, align(center+top, axis.title))))
} else {
Expand Down Expand Up @@ -224,10 +224,8 @@
if axis.location == "bottom" {
place(dx: pos.at(0), dy: 3pt, align(top + center, box(width: length, height: 0pt, [\ #axis.title])))
} else {
style(style => {
let a = measure_axis(axis, style).at(1)
layout(size => place(dy: -size.height - a, align(top + center, box(width: length, height: 0pt, [#axis.title]))))
})
let a = measure_axis(axis).at(1)
layout(size => place(dy: -size.height - a, align(top + center, box(width: length, height: 0pt, [#axis.title]))))
}

// Draws step markings
Expand Down
38 changes: 19 additions & 19 deletions plotst/plotting.typ
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let offset_bottom = 0pt
// Draw coordinate system
for axis in plot.axes {
let (w,h) = measure_axis(axis, style)
let (w,h) = measure_axis(axis)
if(axis.location == "left") {
offset_left += w
}
Expand Down Expand Up @@ -61,7 +61,7 @@
// if you want to make the axes visible (only if plot is set)
//-------
#let prepare_plot(size, caption, plot_code, plot: (), render_axis: true) = {
let (width, height) = if type(size) == "array" {size} else {(size, size)}
let (width, height) = if type(size) == array {size} else {(size, size)}
figure(caption: caption, supplement: "Graph", kind: "plot", {
// Graph box
set align(left + bottom)
Expand Down Expand Up @@ -147,10 +147,10 @@
let step_size_y = calc_step_size(100%, y_axis)
// Places the data points
for (x,y) in plot.data {
if type(x) == "string" {
if type(x) == str {
x = x_axis.values.position(c => c == x)
}
if type(y) == "string" {
if type(y) == str {
y = y_axis.values.position(c => c == y)
}
if stroke != none or fill != none { // DELETEME deprecation, only keep else
Expand Down Expand Up @@ -194,10 +194,10 @@
let step_size_y = calc_step_size(100%, y_axis)
// Places the data points
let data = plot.data.map(((x,y)) => {
if type(x) == "string" {
if type(x) == str {
x = x_axis.values.position(c => c == x)
}
if type(y) == "string" {
if type(y) == str {
y = y_axis.values.position(c => c == y)
}
((x - x_axis.min) * step_size_x, -(y - y_axis.min) * step_size_y)
Expand Down Expand Up @@ -266,8 +266,8 @@
let step_size_x = calc_step_size(100%, x_axis)
let step_size_y = calc_step_size(100%, y_axis)

let array_stroke = type(stroke) == "array"
let array_fill = type(fill) == "array"
let array_stroke = type(stroke) == array
let array_fill = type(fill) == array
// Get count of values
let val_count = 0
for data in plot.data {
Expand Down Expand Up @@ -376,7 +376,7 @@

let data = plot.data

if not type(data.at(0)) == "array" {
if not type(data.at(0)) == array {
let new_data = ((0, data.at(0)),)
for value in data {
let found = false
Expand Down Expand Up @@ -490,14 +490,14 @@
let step_size_y = calc_step_size(100%, y_axis)
// get correct data
let data = transform_data_count(plot.data)
let array_stroke = type(stroke) == "array"
let array_fill = type(fill) == "array"
let array_stroke = type(stroke) == array
let array_fill = type(fill) == array
// draw the bars
if not rotated {
for (idx, data_set) in data.enumerate() {
let height = data_set.at(0) * step_size_y
let x_data = data_set.at(1)
if type(data_set.at(1)) == "string" {
if type(data_set.at(1)) == str {
x_data = x_axis.values.position(c => c == x_data)
}
let x_pos = x_data * step_size_x - if centered_bars {step_size_x * bar_width / 2} else {0pt}
Expand All @@ -510,7 +510,7 @@
for (idx, data_set) in data.enumerate() {
let width = data_set.at(0) * step_size_x
let y_data = data_set.at(1)
if type(data_set.at(1)) == "string" {
if type(data_set.at(1)) == str {
y_data = y_axis.values.position(c => c == y_data)
}
let y_pos = y_data * step_size_y + if centered_bars {step_size_y * bar_width / 2} else {0pt}
Expand Down Expand Up @@ -549,10 +549,10 @@
let y_axis = plot.axes.at(1)
let plot_code() = {
let data = plot.data.map(((x,y)) => {
if type(x) == "string" {
if type(x) == str {
x = x_axis.values.position(c => c == x)
}
if type(y) == "string" {
if type(y) == str {
y = y_axis.values.position(c => c == y)
}
(x,y)
Expand Down Expand Up @@ -643,18 +643,18 @@
data = if pre_calculated {plot.data} else {data}

// let data = transform_data_count(plot.data)
let array_stroke = type(stroke) == "array"
let array_fill = type(fill) == "array"
let array_stroke = type(stroke) == array
let array_fill = type(fill) == array
// draw the boxes
data = if type(data.at(0)) == "array" {
data = if type(data.at(0)) == array {
data
} else {
(data,)
}
for (idx, data_set) in data.enumerate() {
let q(i) = (data_set.at(i) - y_axis.min) * step_size_y
let x_data = data_set.at(5, default: idx + 1)
if type(x_data) == "string" {
if type(x_data) == str {
x_data = x_axis.values.position(c => c == x_data)
}
let box_width = step_size_x * box_width
Expand Down
8 changes: 4 additions & 4 deletions plotst/util/util.typ
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// transforms a data list ((amount, value),..) to a list only containing values
#let transform_data_full(data_count) = {

if not type(data_count.at(0)) == "array" {
if not type(data_count.at(0)) == array {
return data_count
}
let new_data = ()
Expand All @@ -24,7 +24,7 @@

// transforms a data list (val1, val2, ...) to a list looking like this ((amount, val1),...)
#let transform_data_count(data_full) = {
if type(data_full.at(0)) == "array" {
if type(data_full.at(0)) == array {
return data_full
}

Expand All @@ -48,7 +48,7 @@

// converts an integer or 2-long array to a width, height dictionary
#let convert_size(size) = {
if type(size) == "int" { return (width: size, height: size) }
if type(size) == int { return (width: size, height: size) }
if size.len() == 2 { return (width: size.at(0), height: size.at(1)) }
}

Expand All @@ -74,7 +74,7 @@

// range that supports float parameters
#let float_range(min, max, step: 1) = {
if type(min) == "float" or type(max) == "float" or type(step) == "float" {
if type(min) == float or type(max) == float or type(step) == float {
let it = ()
it.push(min)
if step < 0 {
Expand Down