Skip to content

Commit

Permalink
fix tests and corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Jul 19, 2020
1 parent 6fb67cf commit 118b53c
Show file tree
Hide file tree
Showing 25 changed files with 39 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"dependencies": {
"@babel/runtime": "^7.10.5",
"@sgratzl/boxplots": "^1.2.0",
"@sgratzl/boxplots": "^1.2.1",
"@sgratzl/science": "^2.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion samples/animation.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
borderWidth: 1,
outlierRadius: 3,
itemRadius: 3,
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
data: [randomValues(100, 1, 9).concat([14, 16, 0]), randomValues(100, 0, 10)],
},
],
Expand Down
4 changes: 2 additions & 2 deletions samples/datalimits.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
borderColor: window.chartColors.red,
borderWidth: 1,
data: samples.boxplots({ count: 7, random: random }),
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
},
{
label: 'Dataset 2',
backgroundColor: color(window.chartColors.blue).alpha(0.5).rgbString(),
borderColor: window.chartColors.blue,
borderWidth: 1,
data: samples.boxplotsArray({ count: 7, random: random }),
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
},
],
};
Expand Down
3 changes: 1 addition & 2 deletions samples/datastructures.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
backgroundColor: 'rgba(255,0,0,0.2)',
borderColor: 'red',
borderWidth: 1,
outlierColor: '#999999',
padding: 10,
itemRadius: 2,
itemStyle: 'circle',
itemBackgroundColor: '#000',
outlierColor: '#000',
outlierBackgroundColor: '#000',
data: [
[1, 2, 3, 4, 5],
{
Expand Down
6 changes: 3 additions & 3 deletions samples/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
borderColor: window.chartColors.red,
borderWidth: 1,
data: samples.boxplots({ count: 7, random: random }),
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
},
{
label: 'Dataset 2',
backgroundColor: color(window.chartColors.blue).alpha(0.5).rgbString(),
borderColor: window.chartColors.blue,
borderWidth: 1,
data: samples.boxplotsArray({ count: 7, random: random }),
outlierColor: '#999999',
lowerColor: '#461e7d',
outlierBackgroundColor: '#999999',
lowerBackgroundColor: '#461e7d',
},
],
};
Expand Down
2 changes: 1 addition & 1 deletion samples/empty.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
borderWidth: 1,
outlierRadius: 3,
itemRadius: 3,
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
data: [[], randomValues(100, 0, 10)],
},
],
Expand Down
6 changes: 3 additions & 3 deletions samples/items.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
borderWidth: 1,
itemRadius: 2,
data: samples.boxplots({ count: 7, random: random }),
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
},
{
label: 'Dataset 2',
Expand All @@ -49,8 +49,8 @@
borderWidth: 1,
itemRadius: 2,
data: samples.boxplotsArray({ count: 7, random: random }),
outlierColor: '#999999',
lowerColor: '#461e7d',
outlierBackgroundColor: '#999999',
lowerBackgroundColor: '#461e7d',
},
],
};
Expand Down
2 changes: 1 addition & 1 deletion samples/mediancolor.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
borderWidth: 1,
outlierRadius: 3,
itemRadius: 3,
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
data: [randomValues(100, 1, 9).concat([14, 16, 0]), randomValues(100, 0, 10)],
},
],
Expand Down
29 changes: 14 additions & 15 deletions src/controllers/BoxPlotController.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import matchChart from '../__tests__/matchChart';
import { BoxPlotController } from './BoxPlotController';
import { Samples } from './__tests__/utils';
import { registry } from '@sgratzl/chartjs-esm-facade';
import { registry, BarController, LineController, Point, Rectangle, Line } from '@sgratzl/chartjs-esm-facade';
import { BoxAndWiskers } from '../elements';

describe('boxplot', () => {
beforeAll(() => {
registry.addControllers(BoxPlotController);
registry.addElements(BoxAndWiskers);
registry.addControllers(BoxPlotController, BarController, LineController);
registry.addElements(BoxAndWiskers, Point, Rectangle, Line);
});

test('default', () => {
Expand All @@ -23,15 +23,15 @@ describe('boxplot', () => {
backgroundColor: 'red',
borderWidth: 1,
data: samples.boxplots({ count: 7 }),
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
},
{
label: 'Dataset 2',
backgroundColor: 'blue',
borderWidth: 1,
data: samples.boxplotsArray({ count: 7 }),
outlierColor: '#999999',
lowerColor: '#461e7d',
outlierBackgroundColor: '#999999',
lowerBackgroundColor: '#461e7d',
},
],
},
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('boxplot', () => {
borderWidth: 1,
outlierRadius: 3,
itemRadius: 3,
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
data: [
samples.numbers({ count: 100, min: 1, max: 9 }).concat([14, 16, 0]),
samples.numbers({ count: 100, min: 0, max: 10 }),
Expand Down Expand Up @@ -130,16 +130,16 @@ describe('boxplot', () => {
borderWidth: 1,
itemRadius: 2,
data: samples.boxplots({ count: 7 }),
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
},
{
label: 'Dataset 2',
backgroundColor: 'blue',
borderWidth: 1,
itemRadius: 2,
data: samples.boxplotsArray({ count: 7 }),
outlierColor: '#999999',
lowerColor: '#461e7d',
outlierBackgroundColor: '#999999',
lowerBackgroundColor: '#461e7d',
},
],
},
Expand Down Expand Up @@ -233,14 +233,14 @@ describe('boxplot', () => {
backgroundColor: 'red',
borderWidth: 1,
data: samples.boxplots({ count: 7 }),
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
},
{
label: 'Dataset 2',
backgroundColor: 'blue',
borderWidth: 1,
data: samples.boxplotsArray({ count: 7 }),
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
},
],
},
Expand All @@ -266,12 +266,11 @@ describe('boxplot', () => {
backgroundColor: 'rgba(255,0,0,0.2)',
borderColor: 'red',
borderWidth: 1,
outlierColor: '#999999',
padding: 10,
itemRadius: 2,
itemStyle: 'circle',
itemBackgroundColor: '#000',
outlierColor: '#000',
outlierBackgroundColor: '#000',
data: [
[1, 2, 3, 4, 5],
{
Expand Down Expand Up @@ -325,7 +324,7 @@ describe('boxplot', () => {
borderWidth: 1,
outlierRadius: 3,
itemRadius: 3,
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
data: [[], samples.numbers({ count: 100, min: 0, max: 10 })],
},
],
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/ViolinController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ describe('violin', () => {
backgroundColor: 'red',
borderWidth: 1,
data: samples.boxplotsArray({ count: 7 }),
outlierColor: '#999999',
outlierBackgroundColor: '#999999',
},
{
label: 'Dataset 2',
backgroundColor: 'blue',
borderWidth: 1,
data: samples.boxplotsArray({ count: 7 }),
outlierColor: '#999999',
lowerColor: '#461e7d',
outlierBackgroundColor: '#999999',
lowerBackgroundColor: '#461e7d',
},
],
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ function determineStatsOptions(options) {
}

export function boxplotStats(arr, options) {
const r = boxplots(arr, {
coef: options.coef,
quantiles: determineQuantiles(options.quantiles),
});
const r = boxplots(arr, determineStatsOptions(options));
r.whiskerMax = r.whiskerHigh;
r.whiskerMin = r.whiskerLow;
r.outliers = r.outlier;
Expand Down
4 changes: 2 additions & 2 deletions src/elements/BoxAndWiskers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class BoxAndWiskers extends StatsBase {

// Draw the median line
ctx.save();
if (options.medianColor && options.medianColor !== 'none') {
if (options.medianColor && options.medianColor !== 'transparent') {
ctx.strokeStyle = options.medianColor;
}
ctx.beginPath();
Expand All @@ -55,7 +55,7 @@ export class BoxAndWiskers extends StatsBase {

ctx.save();
// fill the part below the median with lowerColor
if (options.lowerBackgroundColor && options.lowerBackgroundColor !== 'none') {
if (options.lowerBackgroundColor && options.lowerBackgroundColor !== 'transparent') {
ctx.fillStyle = options.lowerBackgroundColor;
if (props.q3 > props.q1) {
ctx.fillRect(x0, props.median, width, props.q3 - props.median);
Expand Down
2 changes: 1 addition & 1 deletion src/elements/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const baseRoutes = {
itemBorderColor: 'color',
};

export const baseOptionKeys = /*#__PURE__*/ Object.keys(baseDefaults);
export const baseOptionKeys = /*#__PURE__*/ (() => Object.keys(baseDefaults).concat(Object.keys(baseRoutes)))();

export class StatsBase extends Element {
isVertical() {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1915,10 +1915,10 @@ __metadata:
languageName: node
linkType: hard

"@sgratzl/boxplots@npm:^1.2.0":
version: 1.2.0
resolution: "@sgratzl/boxplots@npm:1.2.0"
checksum: 643f1aae2befbff5d68ff1fb15da5eb0866a8133af10a4dec311efa0533c7d2e2afb243ec5958656ef31c6acec43027a62a2ba53b5eb04ba25d11d5695a7fb9b
"@sgratzl/boxplots@npm:^1.2.1":
version: 1.2.1
resolution: "@sgratzl/boxplots@npm:1.2.1"
checksum: c01aa25f9b23c3f50ed24491d9c37690bd055a9688c3a9e600f310d2b73e27fc0b1d57c3128fe93bf79355e1a4eb2f7e520c1364edb22442b28c971720e4d412
languageName: node
linkType: hard

Expand All @@ -1934,7 +1934,7 @@ __metadata:
"@rollup/plugin-babel": ^5.1.0
"@rollup/plugin-commonjs": ^14.0.0
"@rollup/plugin-node-resolve": ^8.4.0
"@sgratzl/boxplots": ^1.2.0
"@sgratzl/boxplots": ^1.2.1
"@sgratzl/chartjs-esm-facade": ^3.0.0-alpha.2
"@sgratzl/science": ^2.0.0
"@yarnpkg/pnpify": ^2.1.0
Expand Down

0 comments on commit 118b53c

Please sign in to comment.