Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrswift committed Jul 26, 2024
1 parent f94ec0c commit 0167627
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/plot/violin.typ
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@

// bin the data
let (min, max) = (calc.min(..self.data),calc.max(..self.data))
let range = max - min

let binned = self.data.sorted().fold( (0,)*self.bins, (acc, it) => {
let bin = int(calc.rem(5 * (it - min) / (max - min), 5))
acc.insert(bin, acc.at(bin) + 1)
let bin = int(self.bins * (it - min) / (max - min))
acc.at(bin - 1) += 1
return acc
})

self.line-data = ()
self.line-data = binned.enumerate().map( ((x, y)) => {
(0 + y / 10, min + x)
})

// Generate stroke paths
// self.stroke-paths = util.compute-stroke-paths(self.line-data,
// (x.min, y.min), (x.max, y.max))
self.stroke-paths = util.compute-stroke-paths(self.line-data,
(x.min, y.min), (x.max, y.max))

// Compute fill paths if filling is requested
self.fill = self.at("fill", default: false)
Expand All @@ -37,9 +40,9 @@
#let _stroke(self, ctx) = {
let (x, y) = (ctx.x, ctx.y)

// for p in self.stroke-paths {
// draw.line(..p, fill: none)
// }
for p in self.stroke-paths {
draw.line(..p, fill: none)
}
}

#let _fill(self, ctx) = {
Expand Down
1 change: 1 addition & 0 deletions tests/plot/violin/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
plot.plot(size: (9, 6),
// x-tick-step: none,
// y-tick-step: none,
y-max: 10,
{
let vals = (5,4,6,8,5,4,1,5,5,5,4,2,5,4,6,5,4,5,8,4,5,)
cetz-plot.plot.add(vals.map(it=>(0,it)), mark: "x", style: (stroke: none))
Expand Down

0 comments on commit 0167627

Please sign in to comment.