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

Commit

Permalink
Merge pull request #63 from datavisyn/release-2.2.1
Browse files Browse the repository at this point in the history
Release 2.2.1
  • Loading branch information
dg-datavisyn authored Nov 29, 2019
2 parents a731da2 + 8a19ea1 commit 9a3ee5c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chartjs-chart-box-and-violin-plot",
"description": "Chart.js module for charting boxplots",
"version": "2.2.0",
"version": "2.2.1",
"author": {
"name": "datavisyn",
"email": "[email protected]",
Expand Down
23 changes: 16 additions & 7 deletions src/elements/boxandwhiskers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
'use strict';

import * as Chart from 'chart.js';
import ArrayElementBase, {defaults} from './base';
import ArrayElementBase, {
defaults
} from './base';


Chart.defaults.global.elements.boxandwhiskers = {...defaults};
Chart.defaults.global.elements.boxandwhiskers = {
...defaults
};

function transitionBoxPlot(start, view, model, ease) {
const keys = Object.keys(model);
Expand Down Expand Up @@ -58,9 +62,6 @@ const BoxAndWiskers = Chart.elements.BoxAndWhiskers = ArrayElementBase.extend({
const boxplot = vm.boxplot;
const vert = this.isVertical();


this._drawItems(vm, boxplot, ctx, vert);

ctx.save();

ctx.fillStyle = vm.backgroundColor;
Expand All @@ -72,6 +73,8 @@ const BoxAndWiskers = Chart.elements.BoxAndWhiskers = ArrayElementBase.extend({

ctx.restore();

this._drawItems(vm, boxplot, ctx, vert);

},
_drawBoxPlot(vm, boxplot, ctx, vert) {
if (vert) {
Expand Down Expand Up @@ -185,7 +188,10 @@ const BoxAndWiskers = Chart.elements.BoxAndWhiskers = ArrayElementBase.extend({
}

if (vert) {
const {x, width} = vm;
const {
x,
width
} = vm;
const x0 = x - width / 2;
return {
left: x0,
Expand All @@ -194,7 +200,10 @@ const BoxAndWiskers = Chart.elements.BoxAndWhiskers = ArrayElementBase.extend({
bottom: boxplot.whiskerMin
};
}
const {y, height} = vm;
const {
y,
height
} = vm;
const y0 = y - height / 2;
return {
left: boxplot.whiskerMin,
Expand Down
39 changes: 29 additions & 10 deletions src/elements/violin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

import * as Chart from 'chart.js';
import ArrayElementBase, {defaults} from './base';
import ArrayElementBase, {
defaults
} from './base';


Chart.defaults.global.elements.violin = {
Expand Down Expand Up @@ -62,9 +64,6 @@ const Violin = Chart.elements.Violin = ArrayElementBase.extend({
const violin = vm.violin;
const vert = this.isVertical();


this._drawItems(vm, violin, ctx, vert);

ctx.save();

ctx.fillStyle = vm.backgroundColor;
Expand All @@ -82,12 +81,18 @@ const Violin = Chart.elements.Violin = ArrayElementBase.extend({
const width = vm.width;
const factor = (width / 2) / violin.maxEstimate;
ctx.moveTo(x, violin.min);
coords.forEach(({v, estimate}) => {
coords.forEach(({
v,
estimate
}) => {
ctx.lineTo(x - estimate * factor, v);
});
ctx.lineTo(x, violin.max);
ctx.moveTo(x, violin.min);
coords.forEach(({v, estimate}) => {
coords.forEach(({
v,
estimate
}) => {
ctx.lineTo(x + estimate * factor, v);
});
ctx.lineTo(x, violin.max);
Expand All @@ -96,12 +101,18 @@ const Violin = Chart.elements.Violin = ArrayElementBase.extend({
const height = vm.height;
const factor = (height / 2) / violin.maxEstimate;
ctx.moveTo(violin.min, y);
coords.forEach(({v, estimate}) => {
coords.forEach(({
v,
estimate
}) => {
ctx.lineTo(v, y - estimate * factor);
});
ctx.lineTo(violin.max, y);
ctx.moveTo(violin.min, y);
coords.forEach(({v, estimate}) => {
coords.forEach(({
v,
estimate
}) => {
ctx.lineTo(v, y + estimate * factor);
});
ctx.lineTo(violin.max, y);
Expand All @@ -114,6 +125,8 @@ const Violin = Chart.elements.Violin = ArrayElementBase.extend({

ctx.restore();

this._drawItems(vm, violin, ctx, vert);

},
_getBounds() {
const vm = this._view;
Expand All @@ -122,7 +135,10 @@ const Violin = Chart.elements.Violin = ArrayElementBase.extend({
const violin = vm.violin;

if (vert) {
const {x, width} = vm;
const {
x,
width
} = vm;
const x0 = x - width / 2;
return {
left: x0,
Expand All @@ -131,7 +147,10 @@ const Violin = Chart.elements.Violin = ArrayElementBase.extend({
bottom: violin.min
};
}
const {y, height} = vm;
const {
y,
height
} = vm;
const y0 = y - height / 2;
return {
left: violin.min,
Expand Down

0 comments on commit 9a3ee5c

Please sign in to comment.