Skip to content

Commit

Permalink
Merge pull request #148 from sgratzl/release/v4.4.1
Browse files Browse the repository at this point in the history
Release v4.4.1
  • Loading branch information
sgratzl authored Jul 20, 2024
2 parents c43fcd4 + cbdad86 commit df4d831
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 78 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sgratzl/chartjs-chart-boxplot",
"description": "Chart.js module for charting boxplots and violin charts",
"version": "4.4.0",
"version": "4.4.1",
"publishConfig": {
"access": "public"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 18 additions & 14 deletions src/elements/Violin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,36 @@ export class Violin extends StatsBase<IViolinElementProps, IViolinElementOptions
} else {
maxEstimate = props.maxEstimate;
}

ctx.beginPath();
if (this.isVertical()) {
const { x, width } = props;
const factor = width / 2 / maxEstimate;
ctx.moveTo(x, props.min);

props.coords.forEach((c) => {
ctx.lineTo(x - c.estimate * factor, c.v);
});
ctx.lineTo(x, props.max);
ctx.moveTo(x, props.min);
props.coords.forEach((c) => {
ctx.lineTo(x + c.estimate * factor, c.v);
});
ctx.lineTo(x, props.max);

props.coords
.slice()
.reverse()
.forEach((c) => {
ctx.lineTo(x + c.estimate * factor, c.v);
});
} else {
const { y, height } = props;
const factor = height / 2 / maxEstimate;
ctx.moveTo(props.min, y);

props.coords.forEach((c) => {
ctx.lineTo(c.v, y - c.estimate * factor);
});
ctx.lineTo(props.max, y);
ctx.moveTo(props.min, y);
props.coords.forEach((c) => {
ctx.lineTo(c.v, y + c.estimate * factor);
});
ctx.lineTo(props.max, y);

props.coords
.slice()
.reverse()
.forEach((c) => {
ctx.lineTo(c.v, y + c.estimate * factor);
});
}
ctx.closePath();
ctx.stroke();
Expand Down
Loading

0 comments on commit df4d831

Please sign in to comment.