Skip to content

Commit

Permalink
prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Jul 19, 2020
1 parent b08dcea commit 6fb67cf
Show file tree
Hide file tree
Showing 23 changed files with 1,064 additions and 1,124 deletions.
8 changes: 4 additions & 4 deletions 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": "3.0.0-alpha.3",
"version": "3.0.0-alpha.19",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -36,12 +36,12 @@
"src/**/*.js"
],
"peerDependencies": {
"@sgratzl/chartjs-esm-facade": "^3.0.0-alpha.1",
"@sgratzl/chartjs-esm-facade": "^3.0.0-alpha.2",
"chart.js": "^3.0.0-alpha.2"
},
"dependencies": {
"@babel/runtime": "^7.10.5",
"@sgratzl/boxplots": "^1.0.0",
"@sgratzl/boxplots": "^1.2.0",
"@sgratzl/science": "^2.0.0"
},
"devDependencies": {
Expand All @@ -52,7 +52,7 @@
"@rollup/plugin-babel": "^5.1.0",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.4.0",
"@sgratzl/chartjs-esm-facade": "^3.0.0-alpha.1",
"@sgratzl/chartjs-esm-facade": "^3.0.0-alpha.2",
"@yarnpkg/pnpify": "^2.1.0",
"babel-jest": "^26.1.0",
"canvas": "^2.6.1",
Expand Down
3 changes: 2 additions & 1 deletion samples/animation.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<style>
canvas {
Expand Down
3 changes: 2 additions & 1 deletion samples/datalimits.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<script src="https://unpkg.com/d3-random@latest/dist/d3-random.js"></script>
<script src="./utils.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion samples/datastructures.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<script src="https://unpkg.com/d3-random@latest/dist/d3-random.js"></script>
<script src="./utils.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion samples/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<script src="https://unpkg.com/d3-random@latest/dist/d3-random.js"></script>
<script src="./utils.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion samples/default_esm.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<script type="importmap-shim">
{
"imports": {
"chart.js": "https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.esm.js",
"@sgratzl/chartjs-esm-facade": "https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2?module",
"@sgratzl/boxplots": "https://unpkg.com/@sgratzl/boxplots?module",
"@sgratzl/chartjs-chart-boxplot": "../build/Chart.BoxPlot.esm.js"
}
}
Expand Down
3 changes: 2 additions & 1 deletion samples/empty.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<style>
canvas {
Expand Down
5 changes: 4 additions & 1 deletion samples/fivenum.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<style>
canvas {
Expand All @@ -23,6 +24,7 @@
labels: ['A'],
datasets: [
{
itemRadius: 2,
borderColor: 'black',
data: [[18882.492, 7712.077, 5830.748, 7206.05]],
},
Expand All @@ -33,6 +35,7 @@
labels: ['A'],
datasets: [
{
itemRadius: 2,
borderColor: 'black',
data: [[18882.492, 7712.077, 5830.748, 7206.05]],
},
Expand Down
6 changes: 4 additions & 2 deletions samples/horizontalBoxplot.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Horizontal Bar Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<script src="https://unpkg.com/d3-random@latest/dist/d3-random.js"></script>
<script src="./utils.js"></script>
Expand Down Expand Up @@ -50,9 +51,10 @@
window.onload = function () {
var ctx = document.getElementById('canvas').getContext('2d');
window.myBar = new Chart(ctx, {
type: 'horizontalBoxplot',
type: 'boxplot',
data: boxplotData,
options: {
indexAxis: 'y',
responsive: true,
legend: {
position: 'top',
Expand Down
6 changes: 4 additions & 2 deletions samples/horizontalViolin.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Violin Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<script src="https://unpkg.com/d3-random@latest/dist/d3-random.js"></script>
<script src="./utils.js"></script>
Expand Down Expand Up @@ -52,9 +53,10 @@
window.onload = function () {
var ctx = document.getElementById('canvas').getContext('2d');
window.myBar = new Chart(ctx, {
type: 'horizontalViolin',
type: 'violin',
data: boxplotData,
options: {
indexAxis: 'y',
responsive: true,
legend: {
position: 'top',
Expand Down
3 changes: 2 additions & 1 deletion samples/hybrid.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<script src="./utils.js"></script>
<style>
Expand Down
3 changes: 2 additions & 1 deletion samples/items.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<script src="https://unpkg.com/d3-random@latest/dist/d3-random.js"></script>
<script src="./utils.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion samples/logarithm.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<script src="https://unpkg.com/d3-random@latest/dist/d3-random.js"></script>
<script src="./utils.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion samples/mediancolor.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<style>
canvas {
Expand Down
3 changes: 2 additions & 1 deletion samples/minmax.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Box Plot Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<script src="https://unpkg.com/d3-random@latest/dist/d3-random.js"></script>
<script src="./utils.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion samples/violin.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Violin Chart</title>
<script src="https://unpkg.com/chart.js@3.0.0-alpha/dist/Chart.js"></script>
<script src="https://unpkg.com/chart.js@3.0.0-alpha.2/dist/chart.js"></script>
<script src="https://unpkg.com/@sgratzl/chartjs-esm-facade@3.0.0-alpha.2"></script>
<script src="../build/Chart.BoxPlot.js" type="text/javascript"></script>
<script src="https://unpkg.com/d3-random@latest/dist/d3-random.js"></script>
<script src="./utils.js"></script>
Expand Down
7 changes: 3 additions & 4 deletions src/__tests__/matchChart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chart } from '../chart';
import { Chart } from '@sgratzl/chartjs-esm-facade';
const { toMatchImageSnapshot } = require('jest-image-snapshot');

expect.extend({ toMatchImageSnapshot });
Expand Down Expand Up @@ -45,11 +45,10 @@ export default async function matchChart(config, width = 300, height = 300) {
);
const ctx = canvas.getContext('2d');

// sync
Chart.helpers.requestAnimFrame = (c) => c();

const t = new Chart(ctx, config);

await new Promise((resolve) => setTimeout(resolve, 100));

const image = await toBuffer(canvas);
expect(image).toMatchImageSnapshot();
}
4 changes: 2 additions & 2 deletions src/controllers/BoxPlotController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { asBoxPlotStats } from '../data';
import { Chart, BarController, merge } from '@sgratzl/chartjs-esm-facade';
import { Chart, BarController, merge, CategoryScale, LinearScale } from '@sgratzl/chartjs-esm-facade';
import { baseDefaults, StatsBase } from './base';
import { BoxAndWiskers, boxOptionsKeys } from '../elements';
import patchController from './patchController';
Expand Down Expand Up @@ -48,7 +48,7 @@ BoxPlotController.defaults = /*#__PURE__*/ merge({}, [

export class BoxPlotChart extends Chart {
constructor(item, config) {
super(item, patchController(config, BoxPlotController, BoxAndWiskers));
super(item, patchController(config, BoxPlotController, BoxAndWiskers, [CategoryScale, LinearScale]));
}
}
BoxPlotChart.id = BoxPlotController.id;
4 changes: 2 additions & 2 deletions src/controllers/ViolinController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { asViolinStats } from '../data';
import { Chart, merge, BarController } from '@sgratzl/chartjs-esm-facade';
import { Chart, merge, BarController, CategoryScale, LinearScale } from '@sgratzl/chartjs-esm-facade';
import { StatsBase, baseDefaults } from './base';
import { baseOptionKeys } from '../elements/base';
import { Violin } from '../elements';
Expand Down Expand Up @@ -59,7 +59,7 @@ ViolinController.defaults = /*#__PURE__*/ merge({}, [

export class ViolinChart extends Chart {
constructor(item, config) {
super(item, patchController(config, ViolinController, Violin));
super(item, patchController(config, ViolinController, Violin, [CategoryScale, LinearScale]));
}
}
ViolinChart.id = ViolinController.id;
62 changes: 33 additions & 29 deletions src/data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import kde from '@sgratzl/science/src/stats/kde';
import {} from '@sgratzl/boxplots';
export {
quantilesFivenum,
quantilesHigher,
quantilesHinges,
quantilesLinear,
quantilesLower,
quantilesMidpoint,
quantilesNearest,
quantilesType7,
} from '@sgratzl/boxplots';
import boxplots, {
quantilesFivenum,
quantilesHigher,
quantilesHinges,
quantilesLinear,
quantilesLower,
quantilesMidpoint,
quantilesNearest,
quantilesType7,
} from '@sgratzl/boxplots';

/**
* compute the whiskers
Expand Down Expand Up @@ -48,8 +67,8 @@ function determineQuantiles(q) {
return q;
}
const lookup = {
hinges: fivenum,
fivenum: fivenum,
hinges: quantilesHinges,
fivenum: quantilesFivenum,
7: quantilesType7,
quantiles: quantilesType7,
linear: quantilesLinear,
Expand All @@ -72,32 +91,15 @@ function determineStatsOptions(options) {
}

export function boxplotStats(arr, options) {
// console.assert(Array.isArray(arr));
if (arr.length === 0) {
return {
min: NaN,
max: NaN,
median: NaN,
q1: NaN,
q3: NaN,
whiskerMin: NaN,
whiskerMax: NaN,
outliers: [],
};
}

arr = arr.filter((v) => typeof v === 'number' && !Number.isNaN(v));
arr.sort((a, b) => a - b);

const { quantiles, coef } = determineStatsOptions(options);

const stats = quantiles(arr);
const { whiskerMin, whiskerMax } = whiskers(stats, arr, coef);
stats.outliers = arr.filter((v) => v < whiskerMin || v > whiskerMax);
stats.whiskerMin = whiskerMin;
stats.whiskerMax = whiskerMax;
stats.items = arr;
return stats;
const r = boxplots(arr, {
coef: options.coef,
quantiles: determineQuantiles(options.quantiles),
});
r.whiskerMax = r.whiskerHigh;
r.whiskerMin = r.whiskerLow;
r.outliers = r.outlier;
r.items = Array.from(r.items);
return r;
}

export function violinStats(arr, options) {
Expand All @@ -111,6 +113,8 @@ export function violinStats(arr, options) {
const { quantiles } = determineStatsOptions(options);

const stats = quantiles(arr);
stats.min = arr[0];
stats.max = arr[arr.length - 1];
const kdeGen = kde().sample(arr);
// generate coordinates
const range = stats.max - stats.min;
Expand Down
Loading

0 comments on commit 6fb67cf

Please sign in to comment.