Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit 781345c

Browse files
authored
Merge pull request #26 from sepro/master
drawing rects now compatible with canvas2svg
2 parents 2e485cf + 4e66611 commit 781345c

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ rules:
152152
max-nested-callbacks: 0
153153
max-params: 0
154154
max-statements-per-line: 0
155-
max-statements: [2, 40]
155+
max-statements: [2, 43]
156156
multiline-ternary: 0
157157
new-cap: 0
158158
new-parens: 2

package-lock.json

Lines changed: 22 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "chartjs-chart-box-and-violin-plot",
33
"description": "Chart.js module for charting boxplots",
4-
"version": "1.1.2",
4+
"version": "1.2.0",
55
"author": {
66
"name": "Samuel Gratzl",
77
"email": "[email protected]",

src/elements/boxandwhiskers.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,18 @@ const BoxAndWiskers = Chart.elements.BoxAndWhiskers = ArrayElementBase.extend({
7474

7575
},
7676
_drawBoxPlot(vm, boxplot, ctx, vert) {
77-
ctx.beginPath();
7877
if (vert) {
7978
const x = vm.x;
8079
const width = vm.width;
8180
const x0 = x - width / 2;
82-
ctx.fillRect(x0, boxplot.q1, width, boxplot.q3 - boxplot.q1);
83-
ctx.strokeRect(x0, boxplot.q1, width, boxplot.q3 - boxplot.q1);
81+
if (boxplot.q3 > boxplot.q1) {
82+
ctx.fillRect(x0, boxplot.q1, width, boxplot.q3 - boxplot.q1);
83+
ctx.strokeRect(x0, boxplot.q1, width, boxplot.q3 - boxplot.q1);
84+
} else {
85+
ctx.fillRect(x0, boxplot.q3, width, boxplot.q1 - boxplot.q3);
86+
ctx.strokeRect(x0, boxplot.q3, width, boxplot.q1 - boxplot.q3);
87+
}
88+
ctx.beginPath();
8489
ctx.moveTo(x0, boxplot.whiskerMin);
8590
ctx.lineTo(x0 + width, boxplot.whiskerMin);
8691
ctx.moveTo(x, boxplot.whiskerMin);
@@ -91,13 +96,20 @@ const BoxAndWiskers = Chart.elements.BoxAndWhiskers = ArrayElementBase.extend({
9196
ctx.lineTo(x, boxplot.q3);
9297
ctx.moveTo(x0, boxplot.median);
9398
ctx.lineTo(x0 + width, boxplot.median);
99+
ctx.closePath();
100+
ctx.stroke();
94101
} else {
95102
const y = vm.y;
96103
const height = vm.height;
97104
const y0 = y - height / 2;
98-
ctx.fillRect(boxplot.q1, y0, boxplot.q3 - boxplot.q1, height);
99-
ctx.strokeRect(boxplot.q1, y0, boxplot.q3 - boxplot.q1, height);
100-
105+
if (boxplot.q3 > boxplot.q1) {
106+
ctx.fillRect(boxplot.q1, y0, boxplot.q3 - boxplot.q1, height);
107+
ctx.strokeRect(boxplot.q1, y0, boxplot.q3 - boxplot.q1, height);
108+
} else {
109+
ctx.fillRect(boxplot.q3, y0, boxplot.q1 - boxplot.q3, height);
110+
ctx.strokeRect(boxplot.q3, y0, boxplot.q1 - boxplot.q3, height);
111+
}
112+
ctx.beginPath();
101113
ctx.moveTo(boxplot.whiskerMin, y0);
102114
ctx.lineTo(boxplot.whiskerMin, y0 + height);
103115
ctx.moveTo(boxplot.whiskerMin, y);
@@ -108,9 +120,10 @@ const BoxAndWiskers = Chart.elements.BoxAndWhiskers = ArrayElementBase.extend({
108120
ctx.lineTo(boxplot.q3, y);
109121
ctx.moveTo(boxplot.median, y0);
110122
ctx.lineTo(boxplot.median, y0 + height);
123+
ctx.closePath();
124+
ctx.stroke();
111125
}
112-
ctx.stroke();
113-
ctx.closePath();
126+
114127
},
115128
_getBounds() {
116129
const vm = this._view;

0 commit comments

Comments
 (0)